Drupal – Select List “default_value”

After beating my head against the desk the past hour, I finally figured out that to set a default value on a plain select list, you need to use "#value" and not "#default_value". So, for example, say I have an array of banks consisting of the bank id and the bank name, like so:

$banks = array(14=>"bank one", 22=>"bank two);

I then want to construct a simple select form element, this WILL NOT work:

$form['drop'] = array(
 #id' => "bank_drop",
 '#type' => 'select',
 '#title' => 'test',
 '#options' => $banks,
 '<span style="color: #ff0000;">#default_value</span>' =&gt; 22  // will NOT work!
);

But this works:

$form['drop'] = array(
  #id' =&gt; "bank_drop",
  '#type' =&gt; 'select',
  '#title' =&gt; 'test',
  '#options' =&gt; $banks,
  '<span style="color: #339966;"><strong>#value</strong></span>' =&gt; 22  // works!
);

This was on Drupal 6.15

Hope that saves someone some headache :)

This entry was posted in Drupal. Bookmark the permalink.

12 Responses to "Drupal – Select List “default_value”"

Leave a reply