Showing posts with label search. Show all posts
Showing posts with label search. Show all posts

Friday, February 18, 2011

Customizing the Search form - Drupal


To change the label text and text inside the search box and the text on the submit and changing the Submit button image, you can use the following function to do the customizations. You have to add this code in template.php file.

function mytheme_preprocess_search_theme_form(&$vars, $hook) {
// Change the "Search this site" label from the form.
$vars['form']['search_theme_form']['#title'] = t('googling');

// Set a default value for text inside the search box field.
$vars['form']['search_theme_form']['#value'] = t('Find it ..');

// Add a custom class and placeholder text to the search box.
$vars['form']['search_theme_form']['#attributes'] = array('class' => 'NormalTextBox txtSearch', 'onblur' => "if (this.value == '') {this.value = '".$vars['form']['search_theme_form']['#value']."';} ;", 'onfocus' => "if (this.value == '".$vars['form']['search_theme_form']['#value']."') {this.value = '';} ;" );

// 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.gif';

// 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']);
}

Customizing the Search form - Drupal

To change the label text and text inside the search box and the text on the submit and changing the Submit button image, you can use the fo...