Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6084233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:29:50+00:00 2026-05-23T11:29:50+00:00

I am altering the value of the form action for the basic search form

  • 0

I am altering the value of the form action for the basic search form on a Drupal site. Here is the line I added to our hook_form_alter() implementation in our custom search module:

$form_id['#action'] = 'http://mydomain.com/search/customsearchmodule/';

When I view the source for the form, the action is exactly as I have set it in the above line. The problem is, after the form has been submitted, the default search results page is displayed, not the custom search results page.

How do I set the custom search results page to display, rather than the default one?

Edit

Here is an example of my hook_form_alter() implementation:

/**
* Implementation of hook_form_alter()
*/
function mymodule_form_alter(&$form, &$form_state, $form_id) {
  if($form_id == 'search_block_form') {
    $form['#action'] = 'http://www.mydomain.com/search/mymodule/';
  }
}

Also:

I added unset($form['#submit']); to my implementation of hook_form_alter() and, after submitting the form, arrived at the appropriate URL (http://www.mydomain.com/search/mymodule), only without any data passed (no keywords).

Edit #2

I am digging around in the Drupal API and in the core search module just to see how it works. This is the core search_box_form_submit() function from our /modules/search/search.module:

    /**
     * Process a block search form submission.
     */
    function search_box_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($_REQUEST['destination'])) {
        unset($_REQUEST['destination']);
      }
      if (isset($_REQUEST['edit']['destination'])) {
        unset($_REQUEST['edit']['destination']);
      }

      $form_id = $form['form_id']['#value'];
      $form_state['redirect'] = 'search/node/'. trim($form_state['values'][$form_id]);
    }

Note the line where $form_state[‘redirect’] is defined. If I comment this line out, then the search form will land on the search/mymodule/ page, although without any search keywords passed.

Edit – Working Code

The final solution is an altered version of nmc’s answer. I had to alter his mymodule_form_submit() implementation. The function should be named mymodule_submit() and the code within the function needed to be altered as well:

function mymodule_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'])) {
    unset($_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.'));
  }
  else
  {
    $form_id = $form['form_id']['#value'];
    $form_state['redirect'] = 'search/mymodule/'. trim($form_state['values'][$form_id]);
  }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T11:29:50+00:00Added an answer on May 23, 2026 at 11:29 am

    Try changing the submit function which the form calls, instead of changing the URL of the form’s action:

    /**
    * 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'])) {
        unset($_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');
      }
    }
    

    This should redirect the search to http://www.mydomain.com/search/mymodule/keywords which your module can then process the keywords accordingly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am altering the question now! I have the search working using the following:
Hi sorry about my bad terminology. Im using drupal Im using hook form alter
I've created a custom lookup form in Axapta 3.0 in which a user can
I created a module to do all my form altering called form_mods. It's working
'Flex fields' is a term for altering a table at the customer site to
While altering a table (removing a column) in SQL Server 2008, I clicked the
I'm considering altering some tables to use nvarchar(50) as primary key instead of an
Does a tool exist for dynamically altering running javascript in a browser? For example,
Is there a way at all of altering the clipboard of the user via
What is the the best of detecting and later altering the screen resolution and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.