By dubs on
I am using FormsAPI to create a wizard. One of the buttons is "Start Again" which resets a step number to 0. I have the step number as a hidden field on the form, and then use drupal_set_value to alter the value and then return back to the form.
Here's the code: -
This is the part in the form creation code: -
if (!isset($form_values)) {
$step = 1;
} else {
$step = $form_values['step'] + 1;
}
$form['step'] = array(
'#type' => 'hidden',
'#value' => $step,
);This is the code in the validation part (which I know for sure is executed, including the part within the IF block): -
if ($form_state['clicked_button']['#name'] == 'reset') {
form_set_value($form['step'], 0, $form_state);
return $form;
}
No matter what, the "Step" value does not go back to 0....
Thanks,
Dubs
Comments
Try changing the type from
Try changing the type from 'hidden' to 'value'
Seconded. $form['step'] =
Seconded.
Contact me to contract me for D7 -> D10/11 migrations.
Step disappears on Form
Thanks for your answers, but unfortunately it didn't work for me.
The first two lines of my Form code is: -
Step is now missing from the output, and therefore cannot be checked.
What else am I missing?
Thanks,
Dubs
Wrong Approach
Just for reference, I've realised I've been taking the wrong approach.
FormsAPI has a storage area which is perfect for me.
Using $form_state['storage']['step'] = 0; allows me to pass values between the form, validation and submit functions...