如何根据提交的值设置默认值?

时间:2012-01-27 19:18:33

标签: drupal-7

该页面的目的是显示作业列表。顶部的表单可让您过滤结果。提交表单后,我想再次显示表单以及输入的值。如何在drupal中进行此操作。表格代码如下。

function ac_resume_job_list_form($form, &$form_state)
{

  $form['display_options'] = array(
    '#type' => 'fieldset',
    '#title' => 'Display Options',
    '#attributes' => array("style" => "width:250px"),
  );

  $form['display_options']['limit'] = array(
    '#type' => 'textfield',
    '#title' => 'Limit',
    '#size' => 2,
    '#default_value' => 'the value of the submitted form',
  );

  $form['display_options']['submit'] = array(
    '#type' => 'submit',
    '#value' => 'Change Display',
  );


  return $form;
}

1 个答案:

答案 0 :(得分:0)

您需要在表单提交处理程序中设置$form_state['rebuild'] = TRUE,基本上,您可以在重建时访问表单中$form_state变量中的所有提交值:

$default_limit = isset($form_state['values']['limit']) ? $form_state['values']['limit'] : 0; // Or whatever default limit you want to have.

$form['display_options']['limit'] = array(
  '#type' => 'textfield',
  '#title' => 'Limit',
  '#size' => 2,
  '#default_value' => $default_limit
);

// Brief example for the submit form
function my_form_submit($form, &$form_state) {
  $form_state['rebuild'] = TRUE;
}