summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrey Andreev <narf@devilix.net>2014-02-17 21:04:43 +0100
committerAndrey Andreev <narf@devilix.net>2014-02-17 21:04:43 +0100
commitceeafe6e2082fe365c68710024d5546d4c6fa6c4 (patch)
tree19c64c64e836b3374058c26b2885c1d8743ee663
parentffe8aded4d2210759fce3427ed04893e6c655006 (diff)
parent1d03ef480c52546f6016cfda98dd82f341197a17 (diff)
Merge pull request #2881 from brenjt/form_helper
form_dropdown array as first param fix
-rw-r--r--system/helpers/form_helper.php26
1 files changed, 16 insertions, 10 deletions
diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php
index 40852faf8..a724406f0 100644
--- a/system/helpers/form_helper.php
+++ b/system/helpers/form_helper.php
@@ -303,22 +303,20 @@ 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']))
- {
- isset($name['options']) OR $name['options'] = array();
- isset($name['selected']) OR $name['selected'] = array();
- isset($name['extra']) OR $name['extra'] = '';
+ $defaults = array('name' => is_array($data) ? '' : $data);
- return form_dropdown($name['name'], $name['options'], $name['selected'], $name['extra']);
+ if (is_array($data) && isset($data['selected']))
+ {
+ $selected = $data['selected'];
+ unset($data['selected']); // selects don't have a selected attribute
}
is_array($selected) OR $selected = array($selected);
@@ -329,11 +327,19 @@ if ( ! function_exists('form_dropdown'))
$selected = array($_POST[$name]);
}
+ if (is_array($data) && isset($data['options']))
+ {
+ $options = $data['options'];
+ unset($data['options']); // selects don't use an options attribute
+ }
+
+ is_array($options) OR $options = array($options);
+
$extra = _attributes_to_string($extra);
$multiple = (count($selected) > 1 && strpos($extra, 'multiple') === FALSE) ? ' multiple="multiple"' : '';
- $form = '<select name="'.$name.'"'.$extra.$multiple.">\n";
+ $form = '<select '.rtrim(_parse_form_attributes($data, $defaults)).$extra.$multiple.">\n";
foreach ($options as $key => $val)
{