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.

4 Answers 4


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 :( Commented Oct 12, 2012 at 10:42
  • Provide export of your view or screenshot of contextual filters configuration Commented Oct 12, 2012 at 12:48
  • @Mathankumar read my answer once more, I have changed 2nd and 6th items. Commented Oct 17, 2012 at 14:10
  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. Commented Oct 9, 2012 at 13:59
  • IDK if OP solved his problem, but this solution is exactly what I was looking for. Thanks man.
    – GrafiCode
    Commented Oct 3, 2016 at 8:36
  • This works in Drupal 9 and is also available in BEF.
    – Binny
    Commented Jul 7, 2022 at 7:08

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

  $view = views_get_view("VIEW NAME");
  $view->set_display('DISPLAY ID');
  $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 and acknowledge you have read our privacy policy.

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