(Article) Multi-step Forms in Drupal 6 using variable functions

Article : Multi-step Forms in Drupal 6 using variable functions

Goals to develop a multi-step form method

  • One form builder with nested conditional statements is difficult to manage, each step should be its own form array function
  • Steps shouldn't be numbered, e.g. to move to the next step don't $form_state['storage']['step']++
  • Each step should be able to have its own validate and submit handlers
  • Steps should be form alterable

Skip to the attachments for full code example
As far as Form API knows, there is one form builder and thus one validation and submit function. The key is, each piece (builder, validate, and submit function) directs to sub-functions that perform during the appropriate step. Value elements are heavily used to control flow by informing the system what the next step is and for handling step validation and submit.

pseudo-code

We get started with drupal_get_form('main_builder')

function main_builder(form_array) {
Check if we've set our next step

If we have call that step's function and
return it's Form array

If we don't have a step than we're at the
beginning of our form
Call and return first_step()
}

function first_step(form_array) {
Build the form elements we want the user to enter

Define what the next step from this one is
form_array['next_step'] = 'a_single_step'

return form_array
}

function a_single_step(form_array) {
Build the form elements we want the user to enter

Define what the next step from this one is
form_array['next_step'] = 'next_step'

return form_array
}

function main_builder_submit(form_array) {
Store submitted form values

Set next step
}

| Read more..

Courtesy:- Pingv.com