1

I have views block with exposed filters and ajax enabled which was rendered in home page, the problem is when the block is loaded with exposed form views is loading the results too. However I want the results needs to be shown only when the user clicks on the submit button.

If I enable input required, this will work, but the client doesn't want this.

5

Here is the way to solve your issue:

  1. Add Contextual filter of "Global: Null" type
  2. In "When the filter value is NOT available" section check "Provide default value" and specify "Fixed value" and "all". Notice! If view still display results - then try select "Raw value from URL" here.
  3. In "When the filter value IS available or a default is provided" section check "Specify validation criteria" and select "PHP code"
  4. Specify this code

    if (count($view->exposed_input)) { return TRUE; }

  5. In "Action to take if filter value does not validate" select "Display all results for the specified field" value
  6. Don't forget to add any "No results behavior"!

Views filter configuration

Now results will be shown ONLY if filters are sent. View will be empty on first display.

  • still the same behavior, results are shown on first display :( – Mathankumar Oct 12 '12 at 10:42
  • Provide export of your view or screenshot of contextual filters configuration – Eugene Fidelin Oct 12 '12 at 12:48
  • @Mathankumar read my answer once more, I have changed 2nd and 6th items. – Eugene Fidelin Oct 17 '12 at 14:10
3
  1. Edit your view and click on advanced to reveal more options
  2. in the Exposed form block click on Exposed form style - basic
  3. click on the option "input required"

You're done.

  • I don't want to make input as required, mentioned it in the question. – Mathankumar Oct 9 '12 at 13:59
  • IDK if OP solved his problem, but this solution is exactly what I was looking for. Thanks man. – GrafiCode Oct 3 '16 at 8:36
0

Add an exposed filter and hide it( using css etc). When somebody clicks "Apply" then change the hidden filter value using Javascript and submit.

Initially set the exposed filter value to not to generate any View results

-1
  $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);

Just add the above code in a block.

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.