Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By mikebann on
//make a texfield
$form['gameAwayTeam'] = array (
'#type' => 'select',
'#title' => t('Away Team'),
'#options' => $teamName,
'#default_value' => 'test',
);
This is the code in the module i developed. Not sure why but the default value is not being recognized. Has anyone had this problem in the past. is this a bug?
as a work around I just added the value I needed to the beginning of the array with this php function
array_unshift($teamName,'defaultValueHere');
But I'd like to know why the default value isn't being taken.
Thanks,
Mike
Comments
How is $teamName structured?
How is $teamName structured?
It's an array I build from a
It's an array I build from a database call. Other then it being an array what do you mean structured?
Is it a keyed array? Or a
Is it a keyed array? Or a numerical index?
It's keyed I'm defining a
It's keyed I'm defining a specific key for the array so that the value of the array represents the displayed option. Is that the problem? How does drupal deal with an arrays keys.
Try this
This should work
Does this mean that the
Does this mean that the default value is actually referring to the key of the array. I thought it was just adding a new entry. I see why I'm confused now.
Thanks!
That's exactly it. You enter
That's exactly it. You enter the key of the element that you want to be selected.
I have noticed that with
I have noticed that with Firefox the problem lies with the browser. If you look at the html the default is set correctly but not displayed by the browser.