gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 08:00:12 26 4
gpt4 key购买 nike

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;
}

所以基本上我想要一个表单来从数据库中搜索某些内容。点击提交进行搜索,即可得到结果。

我想在同一表单页面的表单下方显示结果。不进入其他页面,仅在原始表单页面。

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

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

最佳答案

您可以将输出表存储在$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;
}

关于drupal 7在自定义模块中提交表单后查询数据库并显示结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15599655/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com