简体   繁体   English

Drupal自定义HTML搜索表单

[英]Drupal Custom HTML Search Form

I would like to display a custom search form in my Drupal site. 我想在我的Drupal网站上显示一个自定义搜索表单。

The search form has just a textbox and a submit button beside it, no need of any hidden fields. 搜索表单旁边只有一个文本框和一个提交按钮,不需要任何隐藏字段。

I tried with a simple html form in my template, that mimics the normal drupal search form: 我在模板中尝试了一个简单的html表单,该表单模仿了普通的drupal搜索表单:

<form accept-charset="UTF-8" id="search-form" method="post" action="/drupal/?q=search/page" class="search-form">
<div id="edit-basic" class="container-inline form-wrapper">
<div class="form-item form-type-textfield form-item-keys">
<input type="text" autocomplete="off" class="form-text" maxlength="255" size="40" name="keys" id="edit-keys" value="search" onBlur="if(this.value == '') { this.value = 'search'; }" onFocus="if(this.value == 'search') { this.value = ''; }" style="right:15px;">
</div>
</div>
<input type="hidden" value="form-Og2HsMomOhfRkoS262LFbqpN2NyIGeHHYfTF43Kynjs" name="form_build_id">
<input type="hidden" value="mfLsAR-y7CVQLcWY7hgZRGPbu3F3R5uQKKpZe3ppAi4" name="form_token">
<input type="hidden" value="search_form" name="form_id">
</form>

But that has got some problem like: “ The form has become outdated. 但这有一些问题,例如:“ 表单已过时。 Copy any unsaved work in the form below and then reload this page. 复制下面表格中所有未保存的作品,然后重新加载此页面。

Is there a way i can use a custom html form as Drupal Search form ? 有没有一种方法可以使用自定义html表单作为Drupal Search表单? Basically i want to redesign the default Drupal search form, to suit my needs. 基本上,我想重新设计默认的Drupal搜索表单,以满足我的需要。

Use the default drupal search form and alter it as needed using hook_form_FORM_ID_alter 使用默认的drupal搜索表单,并根据需要使用hook_form_FORM_ID_alter对其进行更改

/** Implements hook_form_FORM_ID_alter */
function mymodule_form_search_form_alter (& $form, & $form_state)
{
  /* Do your alterations here */
}

Reference the Form API to help learn what changes you need to make. 参考Form API,以帮助您了解需要进行哪些更改。

Rplace mymodule in the code above with the name of your custom module. 用您的自定义模块的名称在上面的代码中放置mymodule。 To output the form, in a template, use the below code: 要输出表单,请在模板中使用以下代码:

$form = drupal_get_form('search_form');
print render($form);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM