summaryrefslogtreecommitdiffstats
path: root/system
diff options
context:
space:
mode:
Diffstat (limited to 'system')
-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"' : '';