summaryrefslogtreecommitdiffstats
path: root/system
diff options
context:
space:
mode:
authorDerek Allard <derek.allard@ellislab.com>2008-01-04 23:26:12 +0100
committerDerek Allard <derek.allard@ellislab.com>2008-01-04 23:26:12 +0100
commit4021b51750afb7e39dc0e5ea6e839c7da4e069ab (patch)
tree24b6d772329756afd79c89fea18c46c01508c555 /system
parent4bbc5c7e832604a468681ea50511f114ef7fb1d5 (diff)
added the ability to have multiple selected items in form_dropdown()
Diffstat (limited to 'system')
-rw-r--r--system/helpers/form_helper.php14
1 files changed, 10 insertions, 4 deletions
diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php
index e591eb74c..a67ea050d 100644
--- a/system/helpers/form_helper.php
+++ b/system/helpers/form_helper.php
@@ -221,18 +221,24 @@ function form_textarea($data = '', $value = '', $extra = '')
* @param string
* @return string
*/
-function form_dropdown($name = '', $options = array(), $selected = '', $extra = '')
+function form_dropdown($name = '', $options = array(), $selected = array(), $extra = '')
{
+ if ( ! is_array($selected))
+ {
+ $selected = array($selected);
+ }
+
if ($extra != '') $extra = ' '.$extra;
-
- $form = '<select name="'.$name.'"'.$extra.">\n";
+ $multiple = (count($selected > 1))?' multiple="multiple"':'';
+
+ $form = '<select name="'.$name.'"'.$extra.$multiple.">\n";
foreach ($options as $key => $val)
{
$key = (string) $key;
$val = (string) $val;
- $sel = ($selected != $key) ? '' : ' selected="selected"';
+ $sel = (in_array($key, $selected))?' selected="selected"':'';
$form .= '<option value="'.$key.'"'.$sel.'>'.$val."</option>\n";
}