1

I like to add a "help tips" link next to the search button. I made some changes on the "search-block-form.tpl.php" (see below) but it does not show on the search result page.

Some documentation on the web suggests using function hook_form_alter to make the changes. Thank you in advance

<div>
  <?php if (empty($variables['form']['#block']->subject)): ?>
    <h2 class="element-invisible"><?php print t('Search form'); ?></h2>
  <?php endif; ?>
  <?php print $search_form; ?>
  <a class="h_tips" href="help_tips">help_tips</a>
</div>

enter image description here

1
  • I presume that code is from search-block-form.tpl.php? Are you sure it's using that exact block though? Have you cleared your caches after modifying the template?
    – Beebee
    Sep 8, 2015 at 14:19

1 Answer 1

1
function MODULENAME_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'search_block_form') {
    $form['help_link'] = array(
      '#markup' => '<a class="h_tips" href="help_tips">help_tips</a>',
    );
  }
}

That should do the work, but I am not sure if the id 'search_block_form' the right one is. If you don't have any custom module, just place this code into your current template's template.php, replace MODULENAME with templatename, save and clear cache.

3
  • I get Parse error: syntax error, unexpected '}', after copy the code below into current template.php, function search_form_alter(&$form, &$form_state, $form_id) { if ($form_id == 'search_block_form') { $form['help_link'] = array( '#markup' => '<a class="h_tips" href="help_tips">help_tips</a>', ) } }
    – Jorge Ben
    Sep 8, 2015 at 17:04
  • Works only for the form id=search_block_form. I wanted to show under search result page, id=search-form. I tried to updated the code with '$form_id == "search-form"' and still would not show. Do you know why? I just added a screenshot for both forms.
    – Jorge Ben
    Sep 9, 2015 at 14:46
  • try "search_form" instead of "search-form" Sep 10, 2015 at 7:04

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.