Drupal exposed view
is there 开发者_C百科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
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:
- remove a logic operator(unlocked) of a exposed filter
- Supplying a predefined list of options for an exposed item in a view in Drupal?
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');
}
}
You can override the form with hook_form_alter
in a custom module.
I don't believe there is a option in the Views UI to display nothing before selection. In your theme you could check if there is an selection, and hide the results if needed.
you can set a default filter (between the exposed ones) with a comparison that is always false.
If a filter is made optional in the exposed filter settings, the view should still display the results...
In Exposed Form Section
change the Exposed
form style from basic
to input required
精彩评论