Drupal Answers is a question and answer site for Drupal developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

My problem is fairly simple. I have written a theme_form() to override the default but I want it to kick in only in the search block. How can I do this with Drupal 7? Thanks

share|improve this question
up vote 2 down vote accepted

Put search-block-form.tpl.php into your theme directory, and modify it as you wish.

Another way is using hook_form_FORM_ID_alter().

 * Implements hook_form_FORM_ID_alter().
function HOOK_form_search_block_form_alter(&$form, &$form_state) {
  $form['#prefix'] = '<div class="custom-wrapper">';
  $form['#suffix'] = '</div>';
share|improve this answer
I didn't try yet your 2nd solution but I want to discuss more the 1st. It looks like search-block-form.tpl.php only uses a variable $search_form which according to the doc, is the complete form ready to output. So I suppose it is just a string and I can't change much in there (unless using regex). Is that right? – TKrugg Dec 25 '12 at 12:48
Yes, that's right. You asked about adding a custom wrapper. So it's enough for this. Otherwise use 2nd solution. It's much more powerful. – ya.teck Dec 27 '12 at 3:39

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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