我正在 Drupal 7 - FAPI 中创建一个多步骤表单。
在主 hook_form() 中,处理了对不同步骤的重定向。
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;
}
在第 2 步中,我有一个可选按钮“添加”,它将 form_values 保存到存储中并重新加载相同的表单(第 2 步)。但是当它重新加载此表单时。以前的表单值被表示为默认表单值,而不是需要的空白(新)表单。
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;
.....
}
}
我尝试在每次提交后手动清除 form_state['values'] 但没有成功。谁能实现这个多步添加另一个功能?