I find no problems with this code...<br><br><span style="font-family: courier new,monospace;">function form_default_some_form() {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> $default = '';</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> $options = array('' => 'none', 'a' => 'a', 'b' => 'b');</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> $form['myform']['mytypes'][$key] = array(</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> '#type' => 'select',</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> '#title' => 'Example select',</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> '#options' => $options,</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> '#default_value' => $default,</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> );</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> return $form;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">}</span><br><br>It performs as expected on D6.16. I thought that the use of an empty string for a key was screwy, but it doesn't seem to affect anything. (But remember, that empty($string) will return TRUE where the string has nothing in it, thus affecting lots of code you might not want to affect.)<br>
<br>Be careful that you don't have your browser tricking you by autofilling the form. Ctrl-refresh or Shift-refresh or clear the cache. Try another browser.<br><br>-Randy<br><br><div class="gmail_quote">On Fri, Apr 30, 2010 at 2:41 PM, Jeff Greenberg <span dir="ltr"><<a href="mailto:jeff@ayendesigns.com">jeff@ayendesigns.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="im">On 4/30/2010 2:58 PM, Randy Fay wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
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>
</blockquote></div>
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>
</blockquote></div><br><br clear="all"><br>-- <br>Randy Fay<br>Drupal Module and Site Development<br><a href="mailto:randy@randyfay.com">randy@randyfay.com</a><br>+1 970.462.7450<br><br>