0

I’ve activated the search form block on my Drupal home page.

When a user enters a keyword and presses search button, I would like to redirect to the search page result.

How can I do that?

  • Can you explain what you mean by "validate button"? What sort of redirection do you need, as submitting the search form will automatically direct the user to the search results page. – Hendrik Nov 6 '15 at 0:29
1
function MyModuleName_form_alter(&$form, &$form_state, $form_id)
{
   if ($form_id == 'search_form_id') {
     $form['#submit'][] = 'MyModuleName_custom_serch_form_submit';
   }  
} 

function MyModuleName_custom_serch_form_submit($form, &$form_state)
{
  if(isset($_GET['q']) && !empty($_GET['q']))
  {    
     $string_serch= $_GET['q'];
    drupal_goto("http://yourdomain.com/search?q=".$string_serch);
  }
}
| improve this answer | |
1

You can redirect search result by using hook_search_box_form_submit

function mytheme_search_box_form_submit($form, &$form_state) {
   $form_state['#redirect'] = 'path of redirect';
}
| improve this answer | |

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