在Drupal6中自定义块搜索表单

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在Drupal6中自定义块搜索表单相关的知识,希望对你有一定的参考价值。

  1. function yourtheme_preprocess_search_block_form(&$vars, $hook) {
  2. // Modify elements of the search form
  3. unset($vars['form']['search_block_form']['#title']);
  4.  
  5. // Set a default value for the search box
  6. $vars['form']['search_block_form']['#value'] = t('Search this site');
  7.  
  8. // Add a custom class to the search box
  9. // Set yourtheme.css > #search-block-form .form-text { color: #888888; }
  10. $vars['form']['search_block_form']['#attributes'] = array(
  11. 'onblur' => "if (this.value == '') {this.value = '".$vars['form']['search_block_form']['#value']."';} this.style.color = '#000000';",
  12. 'onfocus' => "if (this.value == '".$vars['form']['search_block_form']['#value']."') {this.value = '';} this.style.color = '#000000';" );
  13.  
  14. // Modify elements of the submit button
  15. unset($vars['form']['submit']);
  16.  
  17. // Change text on the submit button
  18. //$vars['form']['submit']['#value'] = t('Go!');
  19.  
  20. // Change submit button into image button - NOTE: '#src' leading '/' automatically added
  21. $vars['form']['submit']['image_button'] = array('#type' => 'image_button', '#src' => 'sites/all/themes/yourtheme/images/search-button.png');
  22.  
  23. // Rebuild the rendered version (search form only, rest remains unchanged)
  24. unset($vars['form']['search_block_form']['#printed']);
  25. $vars['search']['search_block_form'] = drupal_render($vars['form']['search_block_form']);
  26.  
  27. // Rebuild the rendered version (submit button, rest remains unchanged)
  28. unset($vars['form']['submit']['#printed']);
  29. $vars['search']['submit'] = drupal_render($vars['form']['submit']);
  30.  
  31. // Collect all form elements to print entire form
  32. $vars['search_form'] = implode($vars['search']);
  33. }

以上是关于在Drupal6中自定义块搜索表单的主要内容,如果未能解决你的问题,请参考以下文章

Drupal 6 中的自定义搜索表单:视图/面板还是自定义 sql?

当自定义模板已应用于节点的内容类型时,如何在 Drupal 6 中自定义特定节点?

Drupal6自定义登录块

Drupal6自定义登录块

根据值在 Admin 中自定义 Django 表单字段

php 在WordPress中自定义登录表单