Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

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
add comment

1 Answer 1

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
add comment

Your Answer

 
discard

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.