From 78a5fc973844c64fe9ead260948b85efaf680da9 Mon Sep 17 00:00:00 2001
From: Derek Allard
Date: Thu, 5 Feb 2009 16:34:35 +0000
Subject: Added the ability to have optgroups in form_dropdown() within the
form helper.
---
system/helpers/form_helper.php | 21 ++++++++++++++++++---
user_guide/changelog.html | 1 +
user_guide/helpers/form_helper.html | 1 +
3 files changed, 20 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 .= ''."\n";
+ }
+ else
+ {
+ $sel = (in_array($key, $selected)) ? ' selected="selected"' : '';
+
+ $form .= '\n";
+ }
}
$form .= '';
diff --git a/user_guide/changelog.html b/user_guide/changelog.html
index 7892dc31e..9a3b613f3 100644
--- a/user_guide/changelog.html
+++ b/user_guide/changelog.html
@@ -82,6 +82,7 @@ SVN Revision:
Helpers
+ - Added the ability to have optgroups in form_dropdown() within the form helper.
- Added a doctype() function to the HTML helper.
- Added ability to force lowercase for url_title() in the URL helper.
diff --git a/user_guide/helpers/form_helper.html b/user_guide/helpers/form_helper.html
index 2bb2a4a3a..8504ac02f 100644
--- a/user_guide/helpers/form_helper.html
+++ b/user_guide/helpers/form_helper.html
@@ -239,6 +239,7 @@ fourth parameter:
echo form_dropdown('shirts', $options, 'large', $js);
+If the array passed as $options is a multidimensional array, form_dropdown() will produce an <optgroup> with the array key as the label.
form_fieldset()
--
cgit v1.2.3-24-g4f1b