How to make a form self referencing in Drupal? Or any other options?(如何在 Drupal 中创建表单自引用?或者有其他选择吗?)
问题描述
我想在我的网站上制作一个自我引用的表格.或者,如果这不是一个选项,例如,我将如何显示我在我的网站中进行的搜索结果?
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']/restuls 页面来处理将向用户显示的内容.
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,您的提交功能应该如下所示:
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 中创建表单自引用?或者有其他选择吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 Drupal 中创建表单自引用?或者有其他选择吗?


- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- PHP - if 语句中的倒序 2021-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01