[development] Array of fields on an admin settings form
nan wich
nan_wich at bellsouth.net
Fri Apr 30 22:21:04 UTC 2010
The #default_value should be the KEY not the value of that array element.
Nancy E. Wichmann, PMP
Injustice anywhere is a threat to justice everywhere. -- Dr. Martin L. King, Jr.
________________________________
From: Jeff Greenberg <jeff at ayendesigns.com>
To: development at drupal.org
Sent: Fri, April 30, 2010 4:41:14 PM
Subject: Re: [development] Array of fields on an admin settings form
On 4/30/2010 2:58 PM, Randy Fay wrote:
> First, use an associative array for your options list, which as you've already discovered is completely wrong in the code you sent out.
> '#options' => array("orange" => t("orange"),... ) or '#options' => array('or' => t('Orange'))... or '#options' => array('1' => t('Orange'), ...)
>
> Second, use only strings for the keys of the associative array (I've seen numeric keys cause some difficulty here in D7 at least)
>
> You don't mention what version of Drupal you're working with.
>
Sorry. It's D6. Ok, made sure of all that, so now in the form field part, I have:
$form['myform']['mytypes'][$key] = array(
'#type' => 'select',
'#title' => t($key),
'#options' => $results_tabs,
'#default_value' => $results_tabs[$val]
);
$results_tabs is an associative array, now defined as $results_tabs => array(''=>'none','a'=>'a','b'=>'b');
$key='a'
$val='a'
When I dpm $forms at the end, it shows, for example,
#default_value=>'a'
and options contains the key/value pairs from $results_tabs, yet the dropdown when the page paints is 'none'
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/development/attachments/20100430/f462bb5f/attachment.html
More information about the development
mailing list