Theme the Search Form in Drupal 6
Description
So it's 1am and you want to theme the search form output of your brand new drupal 6 theme, here's the quick and easy one step guide that will get you though it. Yep, that's right, 1 step, because that's how we do it the agaric way...
Resolution
STEP 1 of 1
Paste the code below into into your trusty template.php file and customize to your heart's desire... (leave out the php open and closing tags, we use em to make the output look nice, with pretty colors and stuff...)
<?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 mytheme_preprocess_search_theme_form(&$vars, $hook) {
// Modify elements of the search form
$vars['form']['search_theme_form']['#title'] = t('Search mysite.com');
// Set a default value for the search box
$vars['form']['search_theme_form']['#value'] = t('Search');
// Add a custom class to the search box
$vars['form']['search_theme_form']['#attributes'] = array('class' => t('cleardefault'));
// 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']);
// 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']);
}
?>
If you want to theme the search block, when pasting the code above into template.php, change all occurrences of "search_theme_form" to "search_block_form" (not forgetting the function name itself).
If you want to delete the box label altogether, replace
$vars['form']['search_theme_form']['#title'] = t('Search mysite.com');with
unset($vars['form']['search_theme_form']['#title']);