Closed (fixed)
Project:
Examples for Developers
Component:
Form Example
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
15 Dec 2010 at 23:47 UTC
Updated:
10 Jan 2011 at 01:20 UTC
Jump to comment: Most recent file
There is a problem with form_example_tutorial_8, the multistep example.
This form does not seem to remember page 2 values when you hit the Back button.
I looked at the back handler (snippet below) and it is definitely trying to record the values, but when I dump the $form_state['values'] there is no reference to any form elements other than the submit buttons...
function form_example_tutorial_8_page_two_back($form, &$form_state) {
$form_state['page_values'][2] = $form_state['values'];
...
I don't know if this a bug in D7, could be I guess. So marking this major for review.
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | examples.form_example_multistep_back_999558_05.patch | 1.43 KB | rfay |
Comments
Comment #1
rfayWhen you do a back button any more, you have to either use #limit_validation_errors() or validate the data in the form before going back. If I remember right in this case we throw away the data. That said, thanks for the bug report and I'll look at it more closely later.
Comment #2
simeThanks for your response Randy. When you say "we throw away the data", are you referring to the example form or to drupal core? I don't see where it would be happening in the example form and I don't see how Drupal knows the difference between the back/next/submit buttons.
FWIW, I played around with lots of variations based on your advice but was no successful.
I note that the values are in there in $form_state['input']. I've been trying to google for documentation about 'limit', but with no luck. I am considering just copying over these values into
$form_state['page_values'][2]to make my own form work but I assume this is somewhat of a hack.Comment #3
simeOk, I worked it out.
The reason I was confused is that in
form_example_tutorial_8_next_submit()the page 2 values are stored as if they will be retained. But storing these values is completely redundant for the reasons you say. Maybe add some comments like this?For other people reading this, the related Drupal core code is in form.inc
drupal_validate_form():Comment #4
rfayThanks for your participation here, @sime.
Just FYI, you put an issue in "Needs review" when you have a patch attached.
Do you want to submit a patch that expresses what you want to fix?
Comment #5
rfayIn #3 I think you showed changes that you intended to put in form_example_tutorial_8_back_submit() in form_example_tutorial_8_page_two_back().
The final reality in the D7 FAPI is that form values have to be either validated or they have to be discarded (which is what happens with #limit_validation_errors = array()). So in the case of a simple back button, discarding is probably the best option, as shown here.
Note that the form_example_wizard.inc goes into a much more extensive discussion of how to do this. Would appreciate your review of that as well.
Here's my patch based on your suggestions.
Comment #6
simeHi rfay, I think those changes would be great, and would help avoid confusion for future trekkers.
(Sorry, I didn't know about the "needs review" being for patches only.)
Comment #7
simeRegarding the Needs Review, it's a bit confusing to be honest. There is no other way to suggest a maintainer should consider a solution! Needs Review is used for non-patch solutions in the, for example, the Webmaster queue all the time.
Comment #8
ilo commentedThank you both! Committed as: http://drupal.org/cvs?commit=469696
Does this need to be back ported?
Comment #9
rfayI don't believe this needs a backport, as the change here was caused by the very-D7 #limit_validation_errors = array().