Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

added possibility to set the attributes parameter as an array or object #1725

Closed
wants to merge 4 commits into from

3 participants

@dododedodonl

Signed-off-by: dododedodonl phpscripter.dodo@gmail.com

@alexbilbie

For the sake of consistency | should be the separator, not / (all of your changes need fixing)

@dododedodonl

@alexbilbie I didn't know what separator to use. Fixed now

@narfbg
Owner

Closing this one, it is outdated and too much of an improvement for a functionality that shouldn't exist in the first place. Add a __toString() method to your objects if you want to pass them directly.

@narfbg narfbg closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 17, 2012
  1. @dododedodonl

    added possibility to set the attributes parameter as an array or object

    dododedodonl authored
    Signed-off-by: dododedodonl <phpscripter.dodo@gmail.com>
  2. @dododedodonl
Commits on Aug 23, 2012
  1. @dododedodonl
  2. @dododedodonl

    Replaced / with | in the function descriptions

    dododedodonl authored
    Signed-off-by: dododedodonl <phpscripter.dodo@gmail.com>
This page is out of date. Refresh to see the latest.
Showing with 27 additions and 28 deletions.
  1. +27 −28 system/helpers/form_helper.php
View
55 system/helpers/form_helper.php
@@ -84,7 +84,7 @@ function form_open($action = '', $attributes = '', $hidden = array())
return $form;
}
}
-
+
// ------------------------------------------------------------------------
if ( ! function_exists('form_open_multipart'))
@@ -173,14 +173,14 @@ function form_hidden($name, $value = '', $recursing = FALSE)
*
* @param mixed
* @param string
- * @param string
+ * @param string|array|object
* @return string
*/
function form_input($data = '', $value = '', $extra = '')
{
$defaults = array('type' => 'text', 'name' => ( ! is_array($data) ? $data : ''), 'value' => $value);
- return '<input '._parse_form_attributes($data, $defaults).$extra." />\n";
+ return '<input '._parse_form_attributes($data, $defaults)._attributes_to_string($extra)." />\n";
}
}
@@ -195,7 +195,7 @@ function form_input($data = '', $value = '', $extra = '')
*
* @param mixed
* @param string
- * @param string
+ * @param string|array|object
* @return string
*/
function form_password($data = '', $value = '', $extra = '')
@@ -221,7 +221,7 @@ function form_password($data = '', $value = '', $extra = '')
*
* @param mixed
* @param string
- * @param string
+ * @param string|array|object
* @return string
*/
function form_upload($data = '', $value = '', $extra = '')
@@ -242,10 +242,12 @@ function form_upload($data = '', $value = '', $extra = '')
{
/**
* Textarea field
+ *
+ * @todo cols/rows override via $extra
*
* @param mixed
* @param string
- * @param string
+ * @param string|array|object
* @return string
*/
function form_textarea($data = '', $value = '', $extra = '')
@@ -263,7 +265,7 @@ function form_textarea($data = '', $value = '', $extra = '')
}
$name = is_array($data) ? $data['name'] : $data;
- return '<textarea '._parse_form_attributes($data, $defaults).$extra.'>'.form_prep($val, $name)."</textarea>\n";
+ return '<textarea '._parse_form_attributes($data, $defaults)._attributes_to_string($extra).'>'.form_prep($val, $name)."</textarea>\n";
}
}
@@ -277,11 +279,12 @@ function form_textarea($data = '', $value = '', $extra = '')
* @param string
* @param array
* @param mixed
- * @param string
+ * @param string|array|object
* @return string
*/
function form_multiselect($name = '', $options = array(), $selected = array(), $extra = '')
{
+ $extra = _attributes_to_string($extra);
if ( ! strpos($extra, 'multiple'))
{
$extra .= ' multiple="multiple"';
@@ -301,7 +304,7 @@ function form_multiselect($name = '', $options = array(), $selected = array(), $
* @param string
* @param array
* @param string
- * @param string
+ * @param string|array|object
* @return string
*/
function form_dropdown($name = '', $options = array(), $selected = array(), $extra = '')
@@ -326,8 +329,10 @@ function form_dropdown($name = '', $options = array(), $selected = array(), $ext
{
$selected = array($_POST[$name]);
}
-
- if ($extra != '')
+
+ $extra = _attributes_to_string($extra);
+
+ if ($extra != '' && strpos($extra, ' ') != 0)
{
$extra = ' '.$extra;
}
@@ -377,7 +382,7 @@ function form_dropdown($name = '', $options = array(), $selected = array(), $ext
* @param mixed
* @param string
* @param bool
- * @param string
+ * @param string|array|object
* @return string
*/
function form_checkbox($data = '', $value = '', $checked = FALSE, $extra = '')
@@ -407,7 +412,7 @@ function form_checkbox($data = '', $value = '', $checked = FALSE, $extra = '')
unset($defaults['checked']);
}
- return '<input '._parse_form_attributes($data, $defaults).$extra." />\n";
+ return '<input '._parse_form_attributes($data, $defaults)._attributes_to_string($extra)." />\n";
}
}
@@ -421,7 +426,7 @@ function form_checkbox($data = '', $value = '', $checked = FALSE, $extra = '')
* @param mixed
* @param string
* @param bool
- * @param string
+ * @param string|array|object
* @return string
*/
function form_radio($data = '', $value = '', $checked = FALSE, $extra = '')
@@ -445,13 +450,13 @@ function form_radio($data = '', $value = '', $checked = FALSE, $extra = '')
*
* @param mixed
* @param string
- * @param string
+ * @param string|array|object
* @return string
*/
function form_submit($data = '', $value = '', $extra = '')
{
$defaults = array('type' => 'submit', 'name' => ( ! is_array($data) ? $data : ''), 'value' => $value);
- return '<input '._parse_form_attributes($data, $defaults).$extra." />\n";
+ return '<input '._parse_form_attributes($data, $defaults)._attributes_to_string($extra)." />\n";
}
}
@@ -464,13 +469,13 @@ function form_submit($data = '', $value = '', $extra = '')
*
* @param mixed
* @param string
- * @param string
+ * @param string|array|object
* @return string
*/
function form_reset($data = '', $value = '', $extra = '')
{
$defaults = array('type' => 'reset', 'name' => ( ! is_array($data) ? $data : ''), 'value' => $value);
- return '<input '._parse_form_attributes($data, $defaults).$extra." />\n";
+ return '<input '._parse_form_attributes($data, $defaults)._attributes_to_string($extra)." />\n";
}
}
@@ -483,7 +488,7 @@ function form_reset($data = '', $value = '', $extra = '')
*
* @param mixed
* @param string
- * @param string
+ * @param string|array|object
* @return string
*/
function form_button($data = '', $content = '', $extra = '')
@@ -495,7 +500,7 @@ function form_button($data = '', $content = '', $extra = '')
unset($data['content']); // content is not an attribute
}
- return '<button '._parse_form_attributes($data, $defaults).$extra.'>'.$content."</button>\n";
+ return '<button '._parse_form_attributes($data, $defaults)._attributes_to_string($extra).'>'.$content."</button>\n";
}
}
@@ -508,7 +513,7 @@ function form_button($data = '', $content = '', $extra = '')
*
* @param string The text to appear onscreen
* @param string The id the label applies to
- * @param string Additional attributes
+ * @param string|array|object Additional attributes
* @return string
*/
function form_label($label_text = '', $id = '', $attributes = array())
@@ -521,13 +526,7 @@ function form_label($label_text = '', $id = '', $attributes = array())
$label .= ' for="'.$id.'"';
}
- if (is_array($attributes) && count($attributes) > 0)
- {
- foreach ($attributes as $key => $val)
- {
- $label .= ' '.$key.'="'.$val.'"';
- }
- }
+ $label .= _attributes_to_string($attributes);
return $label.'>'.$label_text.'</label>';
}
Something went wrong with that request. Please try again.