I'm struggling to redirect the core search form /search/node/* to the search api views /s* .

I took a look at but nothing happens ...


also tried 
function MYMODULE_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'search_form') {
    $form['#action'] = 'search';
    $form['#submit'][] = 'MYMODULE_search_form_submit';
  else if ($form_id == 'search_box_form' || $form_id == 'search_theme_form') {
    $form['#submit'][] = 'MYMODULE_search_form_submit';

function MYMODULE_search_form_submit(&$form, &$form_state) {
  $default = search_get_default_module_info();
  $form_state['redirect'] = str_replace("$default[module]/", '', $form_state['redirect']);

Tried different modules ... but they don't pass the results.. Also tried to add the search form from views on the front page and managed to get it wrong .. all sorts of errors.


  • It was my understanding that you should not use both Drupal core search functionality and the Search API at the same time. The Search API module strongly suggests that you disable core search (at least in Drupal 8).
    – user5013
    Oct 30 '17 at 22:55

The following code will work when saving a node...

function myfunction_form_alter(&$form, &$form_state, $form_id) {

  if ($form_id == 'business_node_form') {
    // redefine our submit handler
    $form['actions']['submit']['#submit'][] = 'myfunction_form_alter_redirect';

function myfunction_form_alter_redirect( $form, &$form_state ){
  $form_state['redirect'] = 'home';

try this function:

* Implementation of hook_form_alter()
function mymodule_form_alter(&$form, &$form_state, $form_id) {
  if($form_id == 'search_block_form') {
    $form['#submit'][] = 'mymodule_form_submit';

 * Process a block search form submission.
function mymodule_form_submit($form, &$form_state) {
  // The search form relies on control of the redirect destination for its
  // functionality, so we override any static destination set in the request,
  // for example by drupal_access_denied() or drupal_not_found()
  // (see http://drupal.org/node/292565).
  if (isset($_GET['destination'])) {

  // Check to see if the form was submitted empty.
  // If it is empty, display an error message.
  // (This method is used instead of setting #required to TRUE for this field
  // because that results in a confusing error message.  It would say a plain
  // "field is required" because the search keywords field has no title.
  // The error message would also complain about a missing #title field.)
  if ($form_state['values']['search_block_form'] == '') {
    form_set_error('keys', t('Please enter some keywords.'));

  $form_id = $form['form_id']['#value'];
  $form_state['redirect'] = 'search/mymodule/'. trim($form_state['values'][$form_id]);
  else {
    form_set_error(NULL, t('Search is currently disabled.'), 'error');

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.