By dsevcik on
I'm trying to override the default value for a dropdown field.
In my module tester, I have
function teachhub_edit_profile_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'user_register_form') {
$form["field_howdidyoufind"]["und"][0]["value"]['#default_value'] = "- Select -";
}
}
This is not working. I tried replacing 0 with "_none" but that did not work either.
Comments
Default value needs to be the
Default value needs to be the key value.
And that looks like a field added to the user object, in which case why not adjust the default setting for the field.
Here is the code below for
Here is the code below for the dropdown in Firebug: Would I change #default_value to "_none"?
- Select a value -Online Search
Social Networking
TeachHUB Email
TeachHUB Newsletter
In-service Event
Word of Mouth
Other
With code: <select
With code:
'_none' would be the correct
'_none' would be the correct value, though you should be able to set the default by configuring the field.
I did this and got a 500
I did this and got a 500 error:
How about
How about trying
From my paste above, the key
From my paste above, the key for that field is already _none. I want to change the display value from the default of "Select a value" to just "Select".
Solved, I looped through the
Solved, I looped through the 2nd tier array and found it:
use language none
use LANGUAGE_NONE instead of 'und'
$form['field_howdidyoufind'][LANGUAGE_NONE]['#options']['_none'] = "- Select -";