Had another look at the form wizard. Studying the code in more detail helped me understand what can be abstracted out of routine multi-page forms processing. It was a good exercise.
For those interested, looks like the cake wizard would save the following code every step of the way: 1. Navigation -------------------- - your code doesn't have to check if the next or previous buttons were pressed, the wizard does this based on the name of the link ("previous" or "next"). - your code doesn't have to figure out which action to call, as that is configured up front in "ways", when you init the wizard. - if you didn't have the wizard, each of your form actions would have to determine if the "Next" or "Previous" link was pressed, then redirect itself to the proper action. - Also, if you have multiple ways through your steps, the wizard handles those transparently to you, so you don't have to check at each step where to go next. For example, if the user is not registered, the wizard will know to first take him to the registration page, then to the login page to login, then back to the page which required login in the first place. (of course, in your validation routines you would have to change the "way" if you see the user is not logged in, I think). 2. Checking for the presence of data ----------------------------------------------------- - the wizard checks to see if there is form data submitted, and if not, calls the current action to redisplay the form with the error messages as appropriate. - if you didn't have the wizard, you would have to perform this check. Not much, but is one less thing to do. 3. Validation ------------------- - the wizard calls the appropriate validation routines you supply each step of the way, and reinvokes the same action (which causes the associated view to be displayed) if there are errors. - if there are no errors, it invokes the action for the next step, according to the "ways" you defined at init time. - If you didn't have the wizard, you would have to call validate yourself (if you had multiple models involved, or custom validation). Again, not much, but something else your code doesn't have to do. 4. Accumulating and storing/ retrieving form data in Sessions ----------------------------------------------------------------------------------------- - after each step, the wizard takes care of storing and accumulating all the form field data in cake sessions, so you don't have to. - after reading and writing all the form variables to the session, the wizard updates everything into the regular cake format $this- >data['model']['field'] style (even though it is managing it underneath in sessions) so you can process it like usual cake programming (ie. both Save validate will find the data). - by using sessions, it eliminates for you some of the data accumulation problems of BACK and FORWARD through the steps, and deals with the session variables transparently to you. Your code doesn't need to be concerned with sessions at all. - if you didn't have the wizard, you would have to manage the form data yourself in sessions, and update the $this->data['model'] ['field'] yourself from the sessions before saving. 5. Clearing the session data at the end --------------------------------------------------------- - after the last step, the wizard clears the session data. - if you didn't have the wizard, you would have to do this yourself. NOTE: all the above is only from reading the code. I have not played with it yet, so please take all the above with a grain of salt, and verify everything for yourself. Question ------------- One of the things I was not sure about - perhaps someone can clarify - the way the wizard invokes your action is: $this->controller->$fct(); // $fct() is the name of your action Does this mean you must put all the actions for that multi-page form into a single controller? What do you do if it makes more sense to have different steps of the form processed by different controllers? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---