Index: components/select.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/components/select.inc,v
retrieving revision 1.18.2.19.2.18
diff -u -r1.18.2.19.2.18 select.inc
--- components/select.inc	23 Jul 2008 06:02:37 -0000	1.18.2.19.2.18
+++ components/select.inc	5 Aug 2008 17:21:32 -0000
@@ -82,6 +82,20 @@
   // Convert the user-entered options list into an array.
   $default_value = _webform_filter_values($component['value'], NULL, NULL, FALSE);
   $options = _webform_select_options($component['extra']['items']);
+  
+  // We need to deal with the situation where optgroup's are specified, but
+  // we're not rendering as a select or a listbox. In this case, we flatten the
+  // options.
+  if ($component['extra']['aslist'] != 'Y') {
+    foreach($options as $optgroup_key => $optgroup) {
+      if (is_array($optgroup)) {
+        foreach ($optgroup as $option => $value) {
+          $options[$option] = $value;
+        }
+        unset($options[$optgroup_key]);
+      }
+    }
+  }
 
   if ($component['extra']['aslist'] == 'Y' && $component['extra']['multiple'] != 'Y') {
     $options = array('' => t('select...')) + $options;
@@ -381,7 +395,13 @@
   $rows = array_filter(explode("\n", _webform_filter_values(trim($text))));
   foreach ($rows as $option) {
     $option = trim($option);
-    if (preg_match('/^([^|]+)\|(.*)$/', $option, $matches)) {
+    
+    // If there are two pipes, the first section is the optgroup label, the
+    // second is the field key, and the third is the selection text.
+    if (preg_match('/^([^|]+)\|([^|]+)\|(.*)$/', $option, $matches)) {
+      $options[$matches[1]][$matches[2]] = $matches[3];
+    }
+    else if (preg_match('/^([^|]+)\|(.*)$/', $option, $matches)) {
       $options[$matches[1]] = $matches[2];
     }
     else {
