summaryrefslogtreecommitdiffstats
path: root/system/helpers/form_helper.php
diff options
context:
space:
mode:
authorDerek Allard <derek.allard@ellislab.com>2008-06-06 13:37:34 +0200
committerDerek Allard <derek.allard@ellislab.com>2008-06-06 13:37:34 +0200
commit1e6ab99c692bb0337559d3303143838dff37d638 (patch)
tree54cab77fefab1ace6be16098bc7b4bc50cad9c22 /system/helpers/form_helper.php
parent7a3b96e27988deeebeeff4469f5de3b9fb50918f (diff)
Form helper refactored to allow form_open() and form_fieldset() to accept arrays or strings as arguments.
Diffstat (limited to 'system/helpers/form_helper.php')
-rw-r--r--system/helpers/form_helper.php70
1 files changed, 51 insertions, 19 deletions
diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php
index c6aa0d2b4..cc08f4fe4 100644
--- a/system/helpers/form_helper.php
+++ b/system/helpers/form_helper.php
@@ -48,18 +48,7 @@ if ( ! function_exists('form_open'))
$form = '<form action="'.$action.'"';
- if ( ! isset($attributes['method']))
- {
- $form .= ' method="post"';
- }
-
- if (is_array($attributes) AND count($attributes) > 0)
- {
- foreach ($attributes as $key => $val)
- {
- $form .= ' '.$key.'="'.$val.'"';
- }
- }
+ $form .= _attributes_to_string($attributes, TRUE);
$form .= '>';
@@ -467,13 +456,7 @@ if ( ! function_exists('form_fieldset'))
$fieldset = "<fieldset";
- if (is_array($attributes) AND count($attributes) > 0)
- {
- foreach ($attributes as $key => $val)
- {
- $fieldset .= ' '.$key.'="'.$val.'"';
- }
- }
+ $fieldset .= _attributes_to_string($attributes, FALSE);
$fieldset .= ">\n";
@@ -610,6 +593,55 @@ if ( ! function_exists('parse_form_attributes'))
}
}
+// ------------------------------------------------------------------------
+
+/**
+ * Attributes To String
+ *
+ * Helper function used by some of the form helpers
+ *
+ * @access private
+ * @param mixed
+ * @param bool
+ * @return string
+ */
+if ( ! function_exists('_attributes_to_string'))
+{
+ function _attributes_to_string($attributes, $formtag = FALSE)
+ {
+ if (is_string($attributes) AND strlen($attributes) > 0)
+ {
+ if ($formtag == TRUE AND strpos($attributes, 'method=') === FALSE)
+ {
+ $attributes .= ' method="post"';
+ }
+
+ return ' '.$attributes;
+ }
+
+ if (is_object($attributes) AND count($attributes) > 0)
+ {
+ $attributes = (array)$attributes;
+ }
+
+ if (is_array($attributes) AND count($attributes) > 0)
+ {
+ $atts = '';
+
+ if ( ! isset($attributes['method']) AND $formtag === TRUE)
+ {
+ $atts .= ' method="post"';
+ }
+
+ foreach ($attributes as $key => $val)
+ {
+ $atts .= ' '.$key.'="'.$val.'"';
+ }
+
+ return $atts;
+ }
+ }
+}
/* End of file form_helper.php */
/* Location: ./system/helpers/form_helper.php */ \ No newline at end of file