I'm customizing my search results page. I have found the two templates search-result.tpl and search-results.tpl but in addition to these there is also a collapsible fieldset for advanced search. Where is this coming from? How can I theme the page as a whole? Like do it in a page.tpl or node.tpl file.

Also Themer tells me that this whole node (the search page content) is actually a block.tpl file! How is that possible?

I'm on D7.

Here is the screenshot:

enter image description here

  • which Drupal 6/7 ? – niksmac May 23 '12 at 6:40
  • 1
    Hey Ali, could you include some code of the pages with the fieldset? – Mike May 23 '12 at 6:41
  • I'm on Drupal 7. – CobaltBabyBear May 23 '12 at 6:41
  • 1
    @Mike Why is there a need for code? The html for the page is a huge mess and I don't think there is enough room on this forum page to put it here. ;) – CobaltBabyBear May 23 '12 at 7:09
  • @Ali I might have been able to point out where the field set comes from. – Mike May 23 '12 at 7:17

The collapsible fieldset comes from FAPI and is a different thing than the search results.

It's a regular form, so you have to alter it the form way, via hooks. The basics are here.

function your_module_name_form_alter (&$form, &$form_state, $form_id)) {
  if ($form_id === 'search_block_form') {  // Double check it's the correct ID
      // Your custom code goes here
      // Starting with a dpm($form) is often a good idea
  • 1
    That's true. But from where does Drupal display the fieldset in the search page because I'm not customizing the form itself? I'm guessing (I could be wrong though) that there might be a template file or something that handles the display of the whole search results content. Where is that? – CobaltBabyBear May 23 '12 at 7:41
  • The fieldset is part of the form, so you should be able to acces it via this hook. – Countzero May 23 '12 at 7:55

You can of course try the default from theme method like Theming forms in Drupal 7

$form['#theme'] = 'foo-login-form';

with hook_form_alter

  • The source of the file you suggest has only one line of code i.e, <?php print $search_form; ?>. And this doesn't tell where the fieldset is coming from. – CobaltBabyBear May 23 '12 at 6:54

The search module outputs a render array to $page['content'] with two parts


You can intercept this array in your theme before it gets rendered and make modifications to it.

i.e in your theme_preprocess_page you can do

$page['content']['search_form']['#suffix'] = 'Hello' 

To insert hello below the form. You can also modify the contents of the arrays directly if you want to change the way they behave.

You will need some logic in there to make sure it exists before making changes. But this is just an example.

Hope that makes sense, there is no single template that surrounds these that you can access directly.


The field set you are seeing is added from node_form_search_form_alter(), which an implementation of hook_form_FORM_ID_alter().

To theme a form, you just need to add code similar to the following one.

function mymodule_form_search_form_alter(&$form, &$form_state, $form_id) {
  if (isset($form['module']) && $form['module']['#value'] == 'node') {
    $form['#theme'] = 'mymodule_search_form';

The theme function could be one using a template file.
The control statement is necessary to add the theme function only to the search form for nodes. If you need to alter all the search pages, then it should be removed; if you need to change another search page, then change the $form['module']['#value'] == 'node' part.

Drupal shows the "Advanced search" fieldset only when the logged-in user has the "use advanced search" permission.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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