Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Modified 'form_dropdown()' to allow an array of attributes for the fi…

…rst parameter, much like other form helper functions.
  • Loading branch information...
commit 3f07e4160aafe5c0e90f65e097e6a83427a9f86c 1 parent 5a3284e
Kevin Wood-Friend authored
Showing with 12 additions and 5 deletions.
  1. +12 −5 system/helpers/form_helper.php
View
17 system/helpers/form_helper.php
@@ -297,7 +297,7 @@ function form_multiselect($name = '', $options = array(), $selected = array(), $
* Drop-down Menu
*
* @access public
- * @param string
+ * @param mixed
* @param array
* @param string
* @param string
@@ -305,8 +305,15 @@ function form_multiselect($name = '', $options = array(), $selected = array(), $
*/
if ( ! function_exists('form_dropdown'))
{
- function form_dropdown($name = '', $options = array(), $selected = array(), $extra = '')
+ function form_dropdown($data = '', $options = array(), $selected = array(), $extra = '')
{
+ if ( ! is_array($data))
+ {
+ $data = array('name' => $data);
+ }
+
+ $defaults = array('name' => $data['name']);
+
if ( ! is_array($selected))
{
$selected = array($selected);
@@ -316,9 +323,9 @@ function form_dropdown($name = '', $options = array(), $selected = array(), $ext
if (count($selected) === 0)
{
// If the form name appears in the $_POST array we have a winner!
- if (isset($_POST[$name]))
+ if (isset($_POST[$data['name']]))
{
- $selected = array($_POST[$name]);
+ $selected = array($_POST[$data['name']]);
}
}
@@ -326,7 +333,7 @@ function form_dropdown($name = '', $options = array(), $selected = array(), $ext
$multiple = (count($selected) > 1 && strpos($extra, 'multiple') === FALSE) ? ' multiple="multiple"' : '';
- $form = '<select name="'.$name.'"'.$extra.$multiple.">\n";
+ $form = '<select '._parse_form_attributes($data, $defaults).$extra.$multiple.">\n";
foreach ($options as $key => $val)
{
Please sign in to comment.
Something went wrong with that request. Please try again.