0

I've created view using Search API Views with two different displays.

First Page display (by_terms) and with the following options:

Page settings: Path:/taxonomy/term/%

Contextual filters: Category: Term ID (indexed)

Filter criteria: Search: Fulltext search (exposed)

And second Content pane display (panel_pane):

Use Panel path: Yes

Filter criteria: Search: Fulltext search (exposed)

Link display: Custom URL set to search/results


When I open page with 1st display /category/list/name (which is alias to /taxonomy/term/123) and submit Search input, it goes to /category/list/name?keywords=test.

When I open page with 2nd display (/search/results) and submit Search input, it goes to /taxonomy/term/%2A?keywords=test which is weird.

Ideally I would like the submit to end up in both cases at /search/results?keywords=test.


Is there any way of controlling the submit URL of the landing page for exposed filter? How?

0

Seems that specific problem is with Panels.

The exposed form is basically a block which have no sense of context, therefore setting the URL from the view pane doesn't affect exposed filters in a block.

Therefore one way to go is to use hook_form_alter:

/**
 * Implements hook_form_alter().
 */
function foo_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'views_exposed_form') {
    $form['#action'] = current_path();
  }
}

Or:

/**
 * Implements hook_form_views_exposed_form_alter().
 */
function foo_form_views_exposed_form_alter(&$form, &$form_state) {
  if ($form['#id'] == 'views-exposed-form-foo-default') { // Or: if ($form['#action'] === '/foo')
    $form['#action'] = '/bar';
  }
}

Or by extending Views handler, for example:

class foo_handler extends views_handler_field {

  /**
   * Add to and alter the form.
   */
  function views_form(&$form, &$form_state) {

    // Submit to the current page if not a page display.
    if ($this->view->display_handler->plugin_name != 'page') {
      $form['#action'] = current_path();
    }
  }

}

Alternatively content pane can be used which can override the path, instead of using exposed form. See this issue for more details.

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.