0

I was looking the insertion point to change some stuff in the search form. I manage to change the search block, but I can't find a way to do the same with the form I see in site.com/search/node I was 100% sure the hook should be function SearchformMod_search_form_alter(&$form, &$form_state, $form_id) { } But it seems like I'm wrong. If I try to use Theme developer I don't get any .tpl suggestion either. Any Idea ?

2 Answers 2

1

The hook you want is hook_form_FORM_ID_alter():

/**
 * Implements hook_form_FORM_ID_alter().
 */
function MYMODULE_form_search_form_alter(&$form, &$form_state, $form_id) {
  // Code here
}

Alternatively you could use hook_form_alter():

/**
 * Implements hook_form_alter().
 */
function MYMODULE_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'search_form') {
    // Code here
  }
}
3
  • I was trying with something like this: function SearchformMod_form_search_form_alter(&$form, &$form_state, $form_id) { $form['#description'] = 'A DESCRIPTION'; } But it doesn't work. The module is enabled. This is why I think the naming wasn't right. The form is the one I see in /search/node
    – aolba
    Commented Feb 19, 2013 at 15:29
  • 1
    @aolba Try something like this instead: $form['custom'] = array('#weight' => 0, '#markup' => 'Hello world!');
    – dxc
    Commented Feb 20, 2013 at 5:49
  • Thank you for the help. This works and help me to keep searching in the right direction. Now I know I have the right name.
    – aolba
    Commented Feb 20, 2013 at 15:07
0

The suggestion MYMODULE_form_search_form_alter() did not work for me. Drupal would not even call it. I ended up using:

function MYMODULE_form_search_block_form_alter(&$form, &$form_state, $form_id) {
  // Code here
}

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.