Extending solution to issue #503 #727

Closed
wants to merge 3 commits into
from
Jump to file or symbol
Failed to load files and symbols.
+17 −6
Diff settings

Always

Just for now

@@ -309,16 +309,25 @@ function form_multiselect($name = '', $options = array(), $selected = array(), $
* Drop-down Menu
*
* @access public
- * @param string
+ * @param mixed
* @param array
* @param string
* @param string
* @return string
*/
if ( ! function_exists('form_dropdown'))
{
- function form_dropdown($name = '', $options = array(), $selected = array(), $extra = '')
+ function form_dropdown($attributes = '', $options = array(), $selected = array(), $extra = '')
{
+ if ( ! is_array($attributes))
+ {
+ $attributes = array('name' => $attributes
+ ,'id' => $attributes

This comment has been minimized.

Show comment Hide comment
@philsturgeon

philsturgeon Dec 1, 2011

Contributor

Weird formatting here!

@philsturgeon

philsturgeon Dec 1, 2011

Contributor

Weird formatting here!

This comment has been minimized.

Show comment Hide comment
@notbenh

notbenh Dec 5, 2011

as in the drop aligned array?

@notbenh

notbenh Dec 5, 2011

as in the drop aligned array?

This comment has been minimized.

Show comment Hide comment
@philsturgeon

philsturgeon Dec 5, 2011

Contributor

Yup, if you want to spread an array over multiple lines please do it like this:

$attributes = array(
    'name' => $attributes,
    'id' => $attributes,
);
@philsturgeon

philsturgeon Dec 5, 2011

Contributor

Yup, if you want to spread an array over multiple lines please do it like this:

$attributes = array(
    'name' => $attributes,
    'id' => $attributes,
);
+ );
+ }
+
+ $defaults = array('name' => $attributes['name']);
+
if ( ! is_array($selected))
{
$selected = array($selected);
@@ -328,17 +337,19 @@ 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[$attributes['name']]))
{
- $selected = array($_POST[$name]);
+ $selected = array($_POST[$attributes['name']]);
}
}
if ($extra != '') $extra = ' '.$extra;
- $multiple = (count($selected) > 1 && strpos($extra, 'multiple') === FALSE) ? ' multiple="multiple"' : '';
+ if (count($selected) > 1 && strpos($extra, 'multiple') === FALSE && !isset($attributes['multiple']) {
+ $attributes[' multiple'] = 'multiple';
+ }
- $form = '<select name="'.$name.'"'.$extra.$multiple.">\n";
+ $form = '<select '._parse_form_attributes($attributes, $defaults).$extra.">\n";
foreach ($options as $key => $val)
{