简体   繁体   English

Drupal搜索主题表单-更改输入类型?

[英]Drupal search theme form - Change input type?

For the theme search box used in Drupal, the text-field is as follows: 对于Drupal中使用的主题搜索框,文本字段如下:

<input type="text" class="form-text" id="edit-search-theme-form-1">

As I am developing a site for mobile, I want to change the input type of the text-field to search. 在开发移动网站时,我想更改要搜索的文本字段的输入类型。

Would anybody know how to go about making this change? 有人知道如何进行此更改吗?

Thanks, Mark. 谢谢马克。

确保在template.php中添加任何新的预处理功能后清除主题缓存

You would have to do HTML5, which actually has a input type "search", but I don't know what the current HTML5 compatibility state of mobile browsers is. 您必须做HTML5,实际上它的输入类型为“搜索”,但我不知道移动浏览器当前的HTML5兼容性状态是什么。 You could try to change the input type with theming. 您可以尝试通过主题更改输入类型。

It is not possible to do with the standard ways. 用标准方法是不可能的。 A list of Drupal form API controls is available here: http://api.drupal.org/api/drupal/developer--topics--forms_api_reference.html/6 这里提供了Drupal表单API控件的列表: http : //api.drupal.org/api/drupal/developer--topics--forms_api_reference.html/6

textfield is used to render <input type="text" textfield用于呈现<input type =“ text”

Perhaps the following hack on the page.tpl.php file in your theme would get what you need: 主题中page.tpl.php文件上的以下hack也许可以满足您的需求:

Immediately after the following code line on your page.tpl.php, 在page.tpl.php上的以下代码行之后,

<?php if ($search_box): ?>

Add, 加,

<?php $search_box = preg_replace ("/<input type=\"text\"/", "<input type=\"search\"", $search_box); ?>

It worked for me. 它为我工作。 Try. 尝试。 :-) :-)

There is another nice solution to this issue that works well in D6 and D7: 对于D6和D7,还有一个很好的解决方案,可以很好地解决此问题:

/**
 * Changes the search form to use the "search" input element of HTML5.
 */
function tao_preprocess_search_block_form(&$vars) {
  $vars['search_form'] = str_replace('type="text"', 'type="search"', $vars['search_form']);
}

This snippet goes into the template.php file of your theme. 该摘录进入主题的template.php文件。 In my case it's tao , that is why the function starts with " tao_ ". 在我的情况下是tao ,这就是为什么函数以“ tao_ ”开头的原因。 You have to rename it to match it your theme name. 您必须重命名它以使其与您的主题名称匹配。

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

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