I have the following multi-page form structure:
- First step: list of products (with checkboxes) and some options like "Edit products..." which are applied to selected products
- Second step: this depends on that option has been selected in the first step, but for example I can have a multi-select control displaying user names
The problem is that the multi-select control does not exist in the first step, I only add it in the second step, and I need to pass some default values to it.
However the Forms API does not process the default values (specified as #default_value) since there was already a submit (at the end of the first step), so I imagine the Forms API is looking for the #value fields instead. Therefore the multi-select control ends up having no selected values on display. (If I would use #value instead of #default_value to submit the initial selected values, then I would not able to query the changed data after the second submit.)
Comments
Comment #1
Péter Cseke commentedI did some debugging and the reason behind this issue is that after the first step the $_POST has been set, so the select will take the actual #value from $_POST instead of taking it from #default_value.
I still have to figure out how to alter this behavior only when the second step loads, but not when the second step is submitted...
Comment #2
Péter Cseke commentedWorkaround
When processing the submit of the first step, we can insert the default selection into $_POST, so the values will be present when loading the second step.
Comment #3
sunThanks for taking the time to report this issue.
However, marking as duplicate of #227817: Multiple Select default_value does not work for multistep forms after first form page. You can follow up on that issue to track its status instead. If any information from this issue is missing in the other issue, please make sure you provide it over there.