summaryrefslogtreecommitdiffstats
path: root/system/helpers
diff options
context:
space:
mode:
authorAndrey Andreev <narf@devilix.net>2014-03-06 12:45:33 +0100
committerAndrey Andreev <narf@devilix.net>2014-03-06 12:45:33 +0100
commit15662dd3d6a21a9602034759129a83e584c3a0d2 (patch)
tree32626dba6347afaecff295627ef80ba40a065fe9 /system/helpers
parentf29fd5b6e1b1a717880918dda0b323c80230e279 (diff)
Fix #2919
Diffstat (limited to 'system/helpers')
-rw-r--r--system/helpers/form_helper.php44
1 files changed, 30 insertions, 14 deletions
diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php
index fe6b6ce11..a23ffcae2 100644
--- a/system/helpers/form_helper.php
+++ b/system/helpers/form_helper.php
@@ -319,30 +319,46 @@ if ( ! function_exists('form_dropdown'))
*/
function form_dropdown($data = '', $options = array(), $selected = array(), $extra = '')
{
- $defaults = array('name' => is_array($data) ? '' : $data);
+ $defaults = array();
- if (is_array($data) && isset($data['selected']))
+ if (is_array($data))
{
- $selected = $data['selected'];
- unset($data['selected']); // selects don't have a selected attribute
+ if (isset($data['selected']))
+ {
+ $selected = $data['selected'];
+ unset($data['selected']); // select tags don't have a selected attribute
+ }
+
+ if (isset($data['options']))
+ {
+ $options = $data['options'];
+ unset($data['options']); // select tags don't use an options attribute
+ }
+ }
+ else
+ {
+ $defaults = array('name' => $data);
}
is_array($selected) OR $selected = array($selected);
+ is_array($options) OR $options = array($options);
// If no selected state was submitted we will attempt to set it automatically
- if (count($selected) === 0 && isset($_POST[$name]))
- {
- $selected = array($_POST[$name]);
- }
-
- if (is_array($data) && isset($data['options']))
+ if (empty($selected))
{
- $options = $data['options'];
- unset($data['options']); // selects don't use an options attribute
+ if (is_array($data))
+ {
+ if (isset($data['name'], $_POST[$data['name']]))
+ {
+ $selected = array($_POST[$data['name']]);
+ }
+ }
+ elseif (isset($_POST[$data]))
+ {
+ $selected = array($_POST[$data]);
+ }
}
- is_array($options) OR $options = array($options);
-
$extra = _attributes_to_string($extra);
$multiple = (count($selected) > 1 && strpos($extra, 'multiple') === FALSE) ? ' multiple="multiple"' : '';