By seanr on
#multistep is no longer valid in Drupal 6, but I can't make heads or tails of what is shown in the upgrade doc:
function my_form($form_state, $param1) {
// standard form definition code goes here...
if (!empty($form_state)) {
$submitted_data = $form_state['values'];
$my_custom_stuff = $form_state['my_data'];
// We're building the form a second time based on previous input...
// Add additional fields, etc.
}
}
function my_form_submit($form, &$form_state) {
// process the form input...
$form_state['rebuild'] = TRUE;
$form_state['my_data'] = 'this will be passed back to the form constructor when the form is rebuilt...';
}
There's just too little there for me to figure out what it should be. Here's my old form stripped down to a bare framework so you can see what I'm trying to do:
function letters_form($form_values = NULL){
$form = array();
$form['#multistep'] = TRUE;
$form['#redirect'] = FALSE;
$step = (!isset($form_values)) ? $form_values['step'] + 1 : 1;
$form['step'] = array(
'#type' => 'hidden',
'#value' => $step,
);
switch ($step) {
case 1:
// first step fields
break;
case 2:
// do something with first step values
// present second step fields
break;
case 3:
// do something with second step values
// present third step fields
break;
}
return $form;
}
function letters_form_validate($form_id,$form_values){
if ($form_values['step'] == 1) {
// validation for the first step
}
if ($form_values['step'] == 2) {
// validation for the second step
}
if ($form_values['step'] == 3) {
// validation for the third step
}
}
function letters_form_submit($form_values){
if ($form_values['step'] == 3) {
// final form submission
return 'some/path';
}
}
It just goes through three steps and does something after the third submission. The problem I'm having a hell of a time wrapping my head around the code in the docs and there are no examples I can find that are detailed enough to get a sense of how it works but not so complex as to be totally overwhelming. I'm also having a very hard time finding any examples that aren't node related.
Comments
No one else gets this stuff
No one else gets this stuff either?
Sean Robertson
webolutionary@webolutionary.com
Sean Robertson | @seanr1978 on twitter
seanr@webolutionary.com
Example
You need to change the callback on the submit button. You need just two functions to do this:
Need help as well
Hi Darren, maybe you could be so kind to help me as well. I have a similar problem. I'm trying to port a module, but have no coding experience. Using the coder module it mention #multistep has been replaced by $form_state. How would that look like in the following function? I'd appreciate any input.
This is what to do
There are some variants for how to make it work. Mine is to use the _validate function to check whether we should submit the form or to go to the next step. Like this (check the comments I added too):
As for the code mariusrooms posted, I don't get how that works. Somehow it seems to combine the form and its validation and submit functions into a single function. That doesn't follow any Forms API version I know, and therefore I don't know how to rework it either.
User Picture Resizer
The code I posted comes from this module: http://drupal.org/project/resizer I was hoping with my non-experience to port it to 6 since it seems no one else will and I really would like to continue using it with Drupal 6. The module seems not to complicated. It could also use some updating to the jquery library as mentioned in one the active tickets there. If anyone has experience porting and is looking for a project, this would be a good one!
Any help would be great.
Regards,
Marius