I’m trying to customize a search box that appears in the global header, using hook_form_alter. I’ve succeeded in changing the submit button to an image but still need to do the following 2 things:

add placeholder text that reads ‘Enter search terms here….’ and then add a

<span class="sb-icon-search"></span> 

within the form itself. This is for future use, i’ll be coding the field to hide/show when mousing over a search icon.

my hook_form_alter code is as follows:

function mytheme_form_alter(&$form, &$form_state, $form_id){
  if($form_id == 'search_block_form'){
  $form[actions][submit]['#type'] = 'image_button';
  $form[actions][submit]['#src'] = drupal_get_path('theme', ‘mytheme’). '/images/search_trans.png';

1 Answer 1


For the placeholder just add this line to the hook_form_alter

$form['FIELD_I_WANT_TO_ALTER']['#attributes']['placeholder'] = 'placeholder text'; 

The span can be done in a few ways but the shortest is

$form['hover_toggle']['#markup'] = '<span class="sb-icon-search"></span>';  

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.