1

The action value for the core search form is /search/node.

How could I get it to go instead to a different url for a custom View?

2 Answers 2

1

if you don't want to do it with code you can use Custom Searchit gives you the possibility to configure it from configuration page:
For node search you can change it from admin/config/search/pages/manage/node_search

2

You can use hook_form_alter or hook_form_FORM_ID_alter to alter a form.

Core's search block form has a form id of search_block_form, so you could implement with hook_form_FORM_ID_alter() like:

use Drupal\Core\Form\FormStateInterface;

function mymodule_form_search_block_form_alter(&$form, FormStateInterface $form_state) {
  $form['#action'] = '/my-custom-path';
}
4
  • Alternatively, you may want to create a custom block with a simple form to submit to your other url.
    – sonfd
    Commented Aug 6, 2020 at 11:20
  • Thanks so much @sonfd. That's a great help. Commented Aug 6, 2020 at 12:25
  • Further question: do you happen to know how I can pass a search word in the url to an exposed filter in a view? I looked for an answer but could not find one. I am trying to use a Search API view with exposed filter for search term, as the search results page. Commented Aug 6, 2020 at 14:05
  • @EdwardPeters - This is a totally different question. You should ask a new one.
    – sonfd
    Commented Aug 24, 2020 at 14:46

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.