<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:arial, helvetica, sans-serif;font-size:14pt"><DIV></DIV>
<DIV>The #default_value should be the KEY not the value of that array element.<BR> </DIV>
<P><FONT face="bookman old style, new york, times, serif" color=#ff007f size=4><EM><STRONG>Nancy E. Wichmann, PMP</STRONG></EM></FONT></P>
<P><FONT face="arial, helvetica, sans-serif">Injustice anywhere is a threat to justice everywhere. -- Dr. Martin L. King, Jr.</FONT></P>
<DIV><BR></DIV>
<DIV style="FONT-SIZE: 14pt; FONT-FAMILY: arial, helvetica, sans-serif"><BR>
<DIV style="FONT-SIZE: 10pt; FONT-FAMILY: arial, helvetica, sans-serif"><FONT face=Tahoma size=2>
<HR SIZE=1>
<B><SPAN style="FONT-WEIGHT: bold">From:</SPAN></B> Jeff Greenberg <jeff@ayendesigns.com><BR><B><SPAN style="FONT-WEIGHT: bold">To:</SPAN></B> development@drupal.org<BR><B><SPAN style="FONT-WEIGHT: bold">Sent:</SPAN></B> Fri, April 30, 2010 4:41:14 PM<BR><B><SPAN style="FONT-WEIGHT: bold">Subject:</SPAN></B> Re: [development] Array of fields on an admin settings form<BR></FONT><BR>On 4/30/2010 2:58 PM, Randy Fay wrote:<BR>> First, use an associative array for your options list, which as you've already discovered is completely wrong in the code you sent out.<BR>> '#options' => array("orange" => t("orange"),... ) or '#options' => array('or' => t('Orange'))... or '#options' => array('1' => t('Orange'), ...)<BR>> <BR>> Second, use only strings for the keys of the associative array (I've seen numeric keys cause some difficulty here in D7 at least)<BR>> <BR>> You don't mention what version of Drupal you're working
with.<BR>> <BR>Sorry. It's D6. Ok, made sure of all that, so now in the form field part, I have:<BR><BR> $form['myform']['mytypes'][$key] = array(<BR> '#type' => 'select',<BR> '#title' => t($key),<BR> '#options' => $results_tabs,<BR> '#default_value' => $results_tabs[$val]<BR> );<BR><BR>$results_tabs is an associative array, now defined as $results_tabs => array(''=>'none','a'=>'a','b'=>'b');<BR>$key='a'<BR>$val='a'<BR><BR>When I dpm $forms at the end, it shows, for example,<BR> #default_value=>'a'<BR>and options contains the key/value pairs from $results_tabs, yet the dropdown when the page paints is 'none'<BR></DIV></DIV></div></body></html>