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
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>';
}
-
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?– TKruggCommented 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.teckCommented Dec 27, 2012 at 3:39