Closed (fixed)
Project:
Views (for Drupal 7)
Version:
7.x-3.3
Component:
exposed filters
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
21 May 2012 at 17:01 UTC
Updated:
11 Jun 2012 at 17:01 UTC
I'm trying to insert a form element with hook_form_alter(), and then i'm trying to set this element as default value.
This is the code:
function custom_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'views_exposed_form' && $form['#id'] == 'views-exposed-form-test-page') {
$form['tid']['#after_build'] = array('_add_default_option_select');
}
if($form['#id'] == 'views-exposed-form-test-page') {
if (empty($_GET['tid'])) {
$form_state['input']['tid'] = 'Select a value';
}
}
}
function _add_default_option_select($element, &$form_state) {
$element['#options'] = array('' => 'Select a value') + $element['#options'];
return ($element);
}
It seems to work but a red frame appears around the new item "Select a value".
This message is also shown:
An illegal choice has been detected. Please contact the site administrator.
Can anyone let me know how to do ?
Thank you
Comments
Comment #0.0
Redart commentedNew code
Comment #1
dawehnerThis should be
There might be some caching going on, so what about hook_form_alter directly.
Comment #2.0
(not verified) commentednew code