I'm creating a multistep form in Drupal 7 - FAPI.
In the main hook_form() the redirection to the different steps are handeled.
function hook_form($form, &$form_state) {
if (empty($form_state['storage']['step'])) {
$form_state['storage']['step'] = 0;
}
switch($form_state['storage']['step']) {
case 0:
$form= _step_0($form, $form_state);
break;
case 1:
$form = _step_1($form, $form_state);
break;
case 2:
$form = _step_2($form, $form_state);
break;
case 3:
$form = _step_3($form, $form_state);
break;
case 99:
$form = _step_end($form, $form_state);
break;
}
return $form;
}
function _step_2($form, &$form_state) {
....
$form['Name'] = array(
'#title' => t('Name'),
'#type' => 'textfield',
'#required' => TRUE,
'#maxlength' => 80,
'#size' => 80,
);
$form['Street'] = array(
'#title' => t('Street'),
'#type' => 'textfield',
'#required' => TRUE,
'#maxlength' => 80,
'#size' => 80,
);
......
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Next',
);
$form['add'] = array(
'#type' => 'submit',
'#value' => 'Collega toevoegen',
);
}
In step 2 I have an optional button 'Add onther' which saves the form_values into storage and reloads the same form (step 2). But when it reloads this form for the seconds time. the previous form values are being represented as default form values and not a blank (new) form, which is wanted.
function inschrijven_form_submit($form, &$form_state) {
switch ($form_state['storage']['step']) {
case 0:
switch($form_state['values']['op']) {
case 'Next' :
....
$form_state['storage']['step'] = 1;
break;
}
break;
case 1:
switch($form_state['values']['op']) {
case 'Next' :
....
$form_state['storage']['step'] = 2;
break;
}
break;
case 2:
switch($form_state['values']['op']) {
case 'Next' :
....
$form_state['storage']['step'] = 3;
break;
case 'Add another' :
$form_state['rebuild'] = TRUE;
....
$form_state['storage']['step'] = 2;
return;
break;
.....
}
}
I've try to clear the form_state['values'] manually after each submit but with no success. Who can this multistep with add another functionality be achieved?