Posted by BayerMeister on February 13, 2011 at 1:35pm
3 followers
Jump to:
| Project: | Drupal core |
| Version: | 6.20 |
| Component: | forms system |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Issue Summary
See http://drupal.org/node/1059694
Steps needed:
1) Create the simplest multi-step form ever.
<?php
function a_form($form_state) {
$num = (int)$form_state['storage']['number'];
$form['Next'] = array(
'#type' => 'submit',
'#value' => $num.'++',
);
return $form;
}
function a_form_submit($form, &$form_state) {
$form_state['storage']['number']++;
}
?>2) Use the form, hit F5 at any time
3) Form will misbehave from the second submission onwards.
Expected behavior:
F5 (refresh) does not fire the submission handler, does not change the content of the form
Current behavior:
When refreshing on further pages of the multi-step form (after the 2nd submission onwards) the submit-handler is somehow fired changing the content of $form_state. In this example it takes you back to after the 1st submission. In more complex examples you get to a completely different place with no apparent logic. The submit handler is fired with submit buttons never pressed before etc.
Comments
#1
Same here ! that is incredible .. I can't find a solution for this. Please help !
#2
This is the soultion I used. At the top of my form_submit I added:
if(isset($form_state['multistep_values']['form_build_id'])) {$form_state['values']['form_build_id'] = $form_state['multistep_values']['form_build_id'];
}
And at the bottom of my form_submit I added:
$form_state['multistep_values']['form_build_id'] = $form_state['values']['form_build_id'];$form_state['rebuild'] = TRUE;
This seemed to retain the form_build_id even when I refreshed my form mid-way through the stages.
I wrote a post on it here: http://davidsonj.com/blog/how-create-multi-step-form-drupal-7
#3
Good stuff! I'll try out your code next time I need a multi-step form. For the moment I think its neat.. Thanks