如何使Drupal中的表单自引用?还是其他选择? [英] How to make a form self referencing in Drupal? Or any other options?
问题描述
我想在我的网站自我介绍中填写一份表单。或者如果这不是一个选择,我该怎么办,例如,显示我在网站上搜索的结果?
I would like to make a form I have in my website self referencing. Or if that's not an option, how would I go for, for example, showing the results of a search I make in my site?
我有一个网站搜索地点,并返回您的偏好的地方列表。目前,我的脚本每次用户搜索时都会创建一个新的节点,但这并不方便。如何更改页面内容,并查看结果而不是搜索表单?
I have a site in which you search for places and it returns a list of places for your preferences. At the moment my script creates a new node every time a user searches but this isn't convenient anymore. How do I change it so that the page content is changed and I see the results instead of the search form?
谢谢,
推荐答案
您应该将表单重定向到传递查询字符串的页面,该字符串用户搜索的字符串,然后在您的搜索/复原中使用$ _GET ['search_param']页面来处理将显示给用户的内容。
You should redirect your form to a page passing a query string with the string of what the user searched and then use $_GET['search_param'] in your search/restuls page to handle what will be displayed to the user.
function yourform_form($form_state) {
$form = array();
//$form['your_search_field']
$form['#submit'][] = 'yourform_form_submit';
return $form;
}
function yourform_form_submit(&$form, $form_state) {
$query = 'search_param='. $form_state['values']['your_search_field'];
drupal_goto('search/results', query);
}
如果您使用Drupal 7,您的提交功能应该如下所示: p>
If you're using Drupal 7 your submit function should look like:
function yourform_form_submit(&$form, $form_state) {
$options['query']['search_param'] = $form_state['values']['your_search_field'];
drupal_goto('search/results', $options);
}
提交后,您应该重定向到 http://yoursite.com/search/results?search_param=my_search_value
After you submit you should be redirected to http://yoursite.com/search/results?search_param=my_search_value
请注意,这种技术由流行的搜索引擎使用:
Note that this technique is used by popular search engines:
https://www.google.com/search?q=my_search_value
这篇关于如何使Drupal中的表单自引用?还是其他选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!