Posted By

fadehelix on 01/31/11


Tagged

template drupal 6 Customize


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

mlangfeld


Customize Block Search Form in Drupal 6


 / Published in: PHP
 

URL: http://drupal.org/node/154137

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

Report this snippet  

You need to login to post a comment.