开发者

Drupal search theme form - Change input type?

开发者 https://www.devze.com 2023-01-26 17:46 出处:网络
For the theme search box used in Drupal, the text-field is as follows: <input type=\"text\" class=\"form-text\" id=\"edit-search-theme-form-1\">

For the theme search box used in Drupal, the text-field is as follows:

<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 makin开发者_JAVA技巧g this change?

Thanks, Mark.


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. 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

textfield is used to render <input type="text"

Perhaps the following hack on the page.tpl.php file in your theme would get what you need:

Immediately after the following code line on your 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:

/**
 * 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. In my case it's tao, that is why the function starts with "tao_". You have to rename it to match it your theme name.


Make sure you clear the theme cache after adding any new preprocess functions in template.php

0

精彩评论

暂无评论...
验证码 换一张
取 消