1

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

1 Answer 1

2

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>';
}
2
  • 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
    Commented Dec 25, 2012 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
    Commented Dec 27, 2012 at 3:39

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.