Drupal 7,表单不会重建

时间:2011-12-22 12:35:32

标签: forms drupal-7 rebuild multi-step

我正在构建一个多步骤表单,如果用户意外刷新页面,我不希望用户丢失任何存储信息。重现的步骤:

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']++;
}

1 个答案:

答案 0 :(得分:1)

值存储在$ form_state ['page_values']中。

$form_state['page_values'][1] = $form_state['values'];

检查API文档中的示例模块以获取更详细的示例。

Example Form

Example Form submit handler to carry values

Validate values(如果需要)