Reputation: 2587
so I have this exposed from and I want to change the default value when the view is displayed. I did search and found many articles on it but either they are for older versions of views or seem to be incomplete or maybe I am wrong somewhere.
Ref articles: drupal.org/node/635242 https://drupal.stackexchange.com/questions/1812/change-the-default-selection-for-a-views-2-exposed-filter
Most of them suggest using hook_form_alter but I think as we are using views hook form alter is called too late. Any help will be much appreciated.
function modulename_form_alter(&$form, $form_state, $form_id) {
if($form['#id'] == 'name-of-the-views-form-displayed') {
if (empty($_GET['label-of-the-filter'])) {
$form_state['input']['label-of-the-filter'] = 'default-value-for-filter';
}
}
}
Upvotes: 1
Views: 2730
Reputation: 66
your function declaration line is missing one &
function modulename_form_alter(&$form, &$form_state, $form_id) {
without it, your changes to the $form_state array get ignored
Upvotes: 2