drupal 7在自定义模块中提交表单后查询数据库并显示结果

All*_*hen 5 drupal

function mymodule_search_form($form, &$form_state) {

  $form..... define the form here

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

  return $form;
}

function mymodule_search_form_submit($form, &$form_state) {

  //process the form and get result 
  $output = this is the result with a table of data.
  //I want to display the result table here.

 //Now I can only use drupal message to display on top.
 drupal_set_message($output);

  return;
}
Run Code Online (Sandbox Code Playgroud)

所以基本上我想要一个表单从数据库中搜索一些东西.点击提交后进行搜索,即可获得结果.

我想在同一表单页面的表单下显示结果. 不要转到另一页,只需在原始表单页面中.

表格可以清理/重置为原始状态,这很好.

http://drupal.org/node/542646 这个讨论是我想要的,但那里看起来没有可靠的结果/解决方案.

Cli*_*ive 10

您可以将输出表存储在$form_state,将表单设置为重建,并在原始表单函数中存在时显示它,例如

function mymodule_search_form($form, &$form_state) {

  $form..... define the form here

  if (!empty($form_state['results_table'])) {
    $form['results_table'] = array('#markup' => $form_state['results_table']);
  }

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

  return $form;
}

function mymodule_search_form_submit($form, &$form_state) {
  $form_state['results_table'] = function_to_get_table();
  $form_state['rebuild'] = TRUE;
}
Run Code Online (Sandbox Code Playgroud)