From 40cd60024d4b18fd26a6cc17ed37cbcc403569e8 Mon Sep 17 00:00:00 2001 From: Brennan Thompson Date: Fri, 14 Feb 2014 12:06:38 -0700 Subject: Made form_dropdown compatible with the other form helper methods --- system/helpers/form_helper.php | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 40852faf8..54e2401be 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -303,22 +303,21 @@ if ( ! function_exists('form_dropdown')) /** * Drop-down Menu * - * @param mixed $name + * @param mixed $data * @param mixed $options * @param mixed $selected * @param mixed $extra * @return string */ - function form_dropdown($name = '', $options = array(), $selected = array(), $extra = '') + function form_dropdown($data = '', $options = array(), $selected = array(), $extra = '') { - // If name is really an array then we'll call the function again using the array - if (is_array($name) && isset($name['name'])) + $name = ! is_array($data) ? $data : ''; + $defaults = array('name' => ( $name)); + + if ( is_array($data) && isset($data['selected'])) { - isset($name['options']) OR $name['options'] = array(); - isset($name['selected']) OR $name['selected'] = array(); - isset($name['extra']) OR $name['extra'] = ''; - - return form_dropdown($name['name'], $name['options'], $name['selected'], $name['extra']); + $selected = $data['selected']; + unset($data['selected']); // selects don't have a selected attribute } is_array($selected) OR $selected = array($selected); @@ -328,13 +327,17 @@ if ( ! function_exists('form_dropdown')) { $selected = array($_POST[$name]); } - - $extra = _attributes_to_string($extra); - + + if ( is_array($data) && isset($data['options'])) + { + $options = $data['options']; + unset($data['options']); // selects don't use an options attribute + } + $multiple = (count($selected) > 1 && strpos($extra, 'multiple') === FALSE) ? ' multiple="multiple"' : ''; - - $form = '\n"; + foreach ($options as $key => $val) { $key = (string) $key; @@ -352,7 +355,7 @@ if ( ! function_exists('form_dropdown')) { $sel = in_array($optgroup_key, $selected) ? ' selected="selected"' : ''; $form .= '\n"; + .(string) $optgroup_val."\n"; } $form .= "\n"; @@ -360,11 +363,11 @@ if ( ! function_exists('form_dropdown')) else { $form .= '\n"; + .(in_array($key, $selected) ? ' selected="selected"' : '').'>' + .(string) $val."\n"; } } - + return $form."\n"; } } -- cgit v1.2.3-24-g4f1b