1 form_example_wizard.inc form_example_wizard_submit($form, &$form_state)

Wizard form submit handler.

This function:

  • Saves away $form_state['values']
  • Process all the form values.

And now comes the magic of the wizard, the function that should handle all the inputs from the user on each different step.

This demonstration handler just do a backdrop_set_message() with the information collected on each different step of the wizard.

Related topics

File

modules/examples/form_example/form_example_wizard.inc, line 299
Extensible wizard form example.

Code

function form_example_wizard_submit($form, &$form_state) {
  $current_step = &$form_state['step'];
  $form_state['step_information'][$current_step]['stored_values'] = $form_state['values'];

  // In this case we've completed the final page of the wizard, so process the
  // submitted information.
  backdrop_set_message(t('This information was collected by this wizard:'));
  foreach ($form_state['step_information'] as $index => $value) {
    // Remove FAPI fields included in the values (form_token, form_id and
    // form_build_id. This is not required, you may access the values using
    // $value['stored_values'] but I'm removing them to make a more clear
    // representation of the collected information as the complete array will
    // be passed through backdrop_set_message().
    unset($value['stored_values']['form_id']);
    unset($value['stored_values']['form_build_id']);
    unset($value['stored_values']['form_token']);

    // Now show all the values.
    backdrop_set_message(t('Step @num collected the following values: <pre>@result</pre>', 
    array(
      '@num' => $index,
      '@result' => print_r($value['stored_values'], TRUE),
    )
    ));
  }
}