我正在构建一个多步骤表单,我不希望用户在不小心刷新页面时丢失任何存储的信息。重现步骤:
1) Press 'ok'-button
2) var_dump($form_state['multistep']['step']) == 2
3) Refresh page
4) var_dump($form_state['multistep']['step']) still == 2
5) Press 'ok'-button
6) var_dump($form_state['multistep']['step']) == 3
7) Refresh page
8) var_dump($form_state['multistep']['step']) == 2 rather than 3
这里一定有一些我不知道的 Drupal 表单机制问题。谁能解释为什么会这样?下面的示例代码。
function multistep_test_form($form, &$form_state) {
if( !isset($form_state['multistep']['step']) ) {
$form_state['multistep']['step'] = 1;
} else {
var_dump($form_state['multistep']['step']);
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'ok'
);
return $form;
}
function multistep_test_form_submit($form, &$form_state) {
$form_state['rebuild'] = TRUE;
$form_state['multistep']['step']++;
}