Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Extending solution to issue #503 #727

Closed
wants to merge 3 commits into from

3 participants

@notbenh

Better name for the attribute array, more consistant, as well as adding the id in the ('name') case.

@philsturgeon philsturgeon commented on the diff
system/helpers/form_helper.php
((6 lines not shown))
{
+ if ( ! is_array($attributes))
+ {
+ $attributes = array('name' => $attributes
+ ,'id' => $attributes

Weird formatting here!

@notbenh
notbenh added a note

as in the drop aligned array?

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

$attributes = array(
    'name' => $attributes,
    'id' => $attributes,
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@narfbg narfbg closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 27, 2011
  1. Modified 'form_dropdown()' to allow an array of attributes for the fi…

    Kevin Wood-Friend authored
    …rst parameter, much like other form helper functions.
Commits on Dec 1, 2011
This page is out of date. Refresh to see the latest.
Showing with 17 additions and 6 deletions.
  1. +17 −6 system/helpers/form_helper.php
View
23 system/helpers/form_helper.php
@@ -309,7 +309,7 @@ function form_multiselect($name = '', $options = array(), $selected = array(), $
* Drop-down Menu
*
* @access public
- * @param string
+ * @param mixed
* @param array
* @param string
* @param string
@@ -317,8 +317,17 @@ 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($attributes = '', $options = array(), $selected = array(), $extra = '')
{
+ if ( ! is_array($attributes))
+ {
+ $attributes = array('name' => $attributes
+ ,'id' => $attributes

Weird formatting here!

@notbenh
notbenh added a note

as in the drop aligned array?

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

$attributes = array(
    'name' => $attributes,
    'id' => $attributes,
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ );
+ }
+
+ $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)
{
Something went wrong with that request. Please try again.