? form.patch
? includes/form.patch
Index: includes/form.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/form.inc,v
retrieving revision 1.324
diff -u -p -r1.324 form.inc
--- includes/form.inc	14 Mar 2009 20:13:26 -0000	1.324
+++ includes/form.inc	26 Mar 2009 21:20:49 -0000
@@ -1454,8 +1454,8 @@ function form_options_flatten($array, $r
     if (is_object($value)) {
       form_options_flatten($value->option, FALSE);
     }
-    elseif (is_array($value)) {
-      form_options_flatten($value, FALSE);
+    elseif (is_array($value) && count(element_children($value))) {
+      form_options_flatten(element_children($value), FALSE);
     }
     else {
       $return[$key] = 1;
@@ -1498,9 +1498,9 @@ function form_select_options($element, $
   $value_is_array = is_array($element['#value']);
   $options = '';
   foreach ($choices as $key => $choice) {
-    if (is_array($choice)) {
+    if (is_array($choice) && count(element_children($choice))) {
       $options .= '<optgroup label="' . $key . '">';
-      $options .= form_select_options($element, $choice);
+      $options .= form_select_options($element, element_children($choice));
       $options .= '</optgroup>';
     }
     elseif (is_object($choice)) {
@@ -1514,7 +1514,16 @@ function form_select_options($element, $
       else {
         $selected = '';
       }
-      $options .= '<option value="' . check_plain($key) . '"' . $selected . '>' . check_plain($choice) . '</option>';
+      if (is_array($choice)) {
+        $value = check_plain($choice['#value']);
+        if ($choice['#attributes']) {
+          $opt_attr = $choice['#attributes'];
+        }
+      }
+      else {
+        $value = check_plain($choice);
+      }
+      $options .= '<option value="'. check_plain($key) .'"'. $selected .' '. drupal_attributes($opt_attr).'>'. $value .'</option>';
     }
   }
   return $options;
