summaryrefslogtreecommitdiffstats
path: root/system/helpers
diff options
context:
space:
mode:
authorDerek Allard <derek.allard@ellislab.com>2009-02-05 17:34:35 +0100
committerDerek Allard <derek.allard@ellislab.com>2009-02-05 17:34:35 +0100
commit78a5fc973844c64fe9ead260948b85efaf680da9 (patch)
tree9bb53969d236d71010ac5d7d142aac085b53be0a /system/helpers
parentabb0adb40486976f137b4d4f42dda5113926a54d (diff)
Added the ability to have optgroups in form_dropdown() within the form helper.
Diffstat (limited to 'system/helpers')
-rw-r--r--system/helpers/form_helper.php21
1 files changed, 18 insertions, 3 deletions
diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php
index c002c6fc0..01d0ea76d 100644
--- a/system/helpers/form_helper.php
+++ b/system/helpers/form_helper.php
@@ -268,11 +268,26 @@ if ( ! function_exists('form_dropdown'))
foreach ($options as $key => $val)
{
$key = (string) $key;
- $val = (string) $val;
- $sel = (in_array($key, $selected))?' selected="selected"':'';
+ if (is_array($val))
+ {
+ $form .= '<optgroup label="'.$key.'">'."\n";
+
+ foreach ($val as $optgroup_key => $optgroup_val)
+ {
+ $sel = (in_array($key, $selected)) ? ' selected="selected"' : '';
+
+ $form .= '<option value="'.$optgroup_key.'"'.$sel.'>'.(string) $optgroup_val."</option>\n";
+ }
- $form .= '<option value="'.$key.'"'.$sel.'>'.$val."</option>\n";
+ $form .= '</optgroup>'."\n";
+ }
+ else
+ {
+ $sel = (in_array($key, $selected)) ? ' selected="selected"' : '';
+
+ $form .= '<option value="'.$key.'"'.$sel.'>'.(string) $val."</option>\n";
+ }
}
$form .= '</select>';