phpdrupalviewdrupal-exposed-filter

Drupal exposed view


is there a way to not display any results initially until the form has been submitted?

Also, I cant see where I can override the exposed form


Solution

  • As @googletorp mentioned, you can override the expose form using hook_form_alter(): check out a couple examples in other questions to get an idea of how it works:

    To display a blank form unless the user fills out the exposed form, you can use hook_views_query_alter() in a custom module:

    function test_views_query_alter(&$view, &$query) {
      $filter_set = FALSE;
    
      foreach ($view->filter as $filter) {
        // Check if we've found a filter identifier that is set
        if ($filter->options['exposed'] && array_key_exists($filter->options['expose']['identifier'], $_GET)) {
          $filter_set = TRUE;
          break;
        }
      }
    
      // If the filter isn't set, add a WHERE clause to the query that
      // cannot be TRUE. This ensures the view returns no results.
      if (!$filter_set) {
        $query->add_where(0, 'FALSE');
      }
    }