0

When visiting a content page (node), I want users to be able to input search terms into a form from there which will be fed into a View via its Views Exposed Filter.

The View I have is contained within Panels in a Panels-based page and it's Views Exposed Filter is made available as an external block. This approach allows me to layout this View and Views Exposed Filter with other separate items in other Panels.

Given that the Views Exposed Filter is made available as an external block, I can display it on other pages such as content. However, entering search into this form on these content pages results in the just the View being displayed - I need it to display the Panels-based page as mentioned above with the View results.

So I would somehow need to feed the input supplied by the user into the form on the content page, as a parameter into the Panels-based page.

My initial thoughts and questions on implementaton

Is it a case of using something like dpm() (which I have found useful in the past) to understand the form data being input so that input from the form can be fed to the Panels-based page and 'routed' to the Views Exposed Filter? I think the form data needed by the Views Exposed Filter is understood but how would I know where to submit the data i.e. can I give the URL for the Panels-based page as the form action URL and is there anything else I need to do so that the Panels-based page will convey the form input data to the Views Exposed Filter in the panel?

2 Answers 2

1

It is possible to use dpm() to understand the form data. In a custom module, you can use hook_form_alter() to act on the exposed filter form.

It would look something like this:

function example_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'views_exposed_form') {
    dpm($form);
  }
}

You can then set the action.

function example_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'views_exposed_form') {
    $form['#action'] = '/path-to-panel';
  }
}

Just beware that this will alter all the exposed filters on the site. You can create a different if statement to target them more specifically if you have more than one.

0
0

Another option might be to Render view's exposed form anywhere in a theme/module Credit: timonweb

Quoted here for convenience (and in case entry gets deleted):

/**
 * Returns rendered exposed form for a given view.
 * $view_name
 * - A string with a view name,
 * $display_id
 * - A string with a name of view display,
 * @return
 *  Rendered exposed form.
 */
function MY_MODULE_render_exposed_form($view_name, $display_id = 'page') {
  $view = views_get_view($view_name);
  $view->set_display($display_id);
  $view->init_handlers();
  $form_state = array(
    'view' => $view,
    'display' => $view->display_handler->display,
    'exposed_form_plugin' => $view->display_handler->get_plugin('exposed_form'),
    'method' => 'get',
    'rerender' => TRUE,
    'no_redirect' => TRUE,
  );
  $form = drupal_build_form('views_exposed_form', $form_state);
  return drupal_render($form);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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