0
我剛剛在以下位置上傳了測試網站:www.betterclassofleaders.co.cc/whackk 我正在使用自定義搜索框(通過search-theme-form.tpl.php )但它不起作用。如果您鍵入搜索字詞並按Enter鍵,則會轉到搜索結果頁面,但不會實際執行搜索。搜索框在Drupal中不起作用
通過搜索結果頁確實正常工作。任何想法可能是什麼問題?
我剛剛在以下位置上傳了測試網站:www.betterclassofleaders.co.cc/whackk 我正在使用自定義搜索框(通過search-theme-form.tpl.php )但它不起作用。如果您鍵入搜索字詞並按Enter鍵,則會轉到搜索結果頁面,但不會實際執行搜索。搜索框在Drupal中不起作用
通過搜索結果頁確實正常工作。任何想法可能是什麼問題?
顯然,您不能直接修改search-theme-form.tpl.php
中的HTML,因爲那不是正確的方法。所以我添加類和onFocus和onBlur屬性是問題所在。
正確的做法是修改主題template.php
文件。基本上我們將使用form_alter()
來修改表單元素。由於使用HTML方式是錯誤的。看看下面的代碼(摘自:here)
<?php
/**
* Override or insert PHPTemplate variables into the search_theme_form template.
*
* @param $vars
* A sequential array of variables to pass to the theme template.
* @param $hook
* The name of the theme function being called (not used in this case.)
*/
function yourthemename_preprocess_search_theme_form(&$vars, $hook) {
// Note that in order to theme a search block you should rename this function
// to yourthemename_preprocess_search_block_form and use
// 'search_block_form' instead of 'search_theme_form' in the customizations
// bellow.
// Modify elements of the search form
$vars['form']['search_theme_form']['#title'] = t('');
// Set a default value for the search box
$vars['form']['search_theme_form']['#value'] = t('Search this Site');
// Add a custom class and placeholder text to the search box
$vars['form']['search_theme_form']['#attributes'] = array('class' => 'NormalTextBox txtSearch',
'onfocus' => "if (this.value == 'Search this Site') {this.value = '';}",
'onblur' => "if (this.value == '') {this.value = 'Search this Site';}");
// Change the text on the submit button
//$vars['form']['submit']['#value'] = t('Go');
// Rebuild the rendered version (search form only, rest remains unchanged)
unset($vars['form']['search_theme_form']['#printed']);
$vars['search']['search_theme_form'] = drupal_render($vars['form']['search_theme_form']);
$vars['form']['submit']['#type'] = 'image_button';
$vars['form']['submit']['#src'] = path_to_theme() . '/images/search.jpg';
// Rebuild the rendered version (submit button, rest remains unchanged)
unset($vars['form']['submit']['#printed']);
$vars['search']['submit'] = drupal_render($vars['form']['submit']);
// Collect all form elements to make it easier to print the whole form.
$vars['search_form'] = implode($vars['search']);
}
?>
在yourthemename_preprocess_search_theme_form
- 「yourthemename」將明顯地反映出您的自定義主題的名稱。基本上,代碼是不言自明的。什麼與評論和所有。
所以,基本上這就是它的工作方式。
請提供search-theme-form.tpl.php模板文件。我想你可能已經忘記了表單行爲。 – Alexar 2010-02-28 16:49:42
」/> – bcosynot 2010-05-18 10:51:09