Hi peeps,
I'm struggling to create a wizard style multipart form module for Drupal 5. The module is for job application. It should look like this:
Step 1 (fill some fields) -> Step 2 (fill some fields) -> (...) -> Step x (see all the data to verify) -> Final step (submit)
I decided neither to use sessions nor hidden fields since the former get very thrashy with loads of data and the latter make page considerably bigger (since each step has quite a lot of fields). I store the temporary form values in drupal cache. As the site is on a dedicated server caching this data won't impact performance much (me thinks ;) ). This works really ok, but there is one tiny problem - the 'back' button. I made a back button - hitting it loads a previous form and fill in fields' default values with data from cache. Easy and it works. The only problem is that the 'back' button works only if all the required fields are filled (so one cannot go back without actually filling the current form). Is there any civilized way (I mean using the Drupal API ;) ) to overcome this? :)
Thanks in advance for your suggestions! :)
Comments
The Back Button
I don't think there's any easy way to deal with the back button. In my multi-page form module (currently only supporting v4.7: http://drupal.org/project/multiforms), I include logic to deal with this, but the logic is a bit kludgy (if memory serves, I use a session variable to mark which form sections have been completed so as not insert new data when editing is what's needed).
-Mike Cantelon
http://mikecantelon.com
Is it validation?
Is the form failing to validate when you hit the back button? What if you turn off the "required" attribute for all fields, and manually set the classes in the form builder function (possibly with the #prefix attribute). Then do validation manually for each field in the _validate function. If the back button has been pressed, you can skip the validation completely.
Chris.
http://www.trailheadinteractive.com
--- Featured Projects ---
http://www.montanakitesports.com
http://www.cmrussell.org
http://www.tdandh.com
http://www.cccsmt.org
http://www.universalsemensales.com
http://www.trailheadinteractive.com
Maybe of Use
I have published a module and some doco for my company. It's here:
http://www.pre-emptive.net/doco/drupal-5-wizard-api-module
It does most of what you need, although does use $_SESSION. Be aware, with Drupal 5.1 the module runs into a few bugs which cause problems for heavy use of wizard forms.
Once some more doco is done, I'll be looking at a Drupal 6 version of this module. We have a "transitional" version already working, and it's looking good so far. More on that as it comes...