Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

form_hidden() - added an optional parameter to add attributes

  • Loading branch information...
commit 4438cbc23c58a3cec258c9eda58b867fb0f4ab53 1 parent 4d509d6
@JFox-sk authored
View
17 system/helpers/form_helper.php
@@ -129,11 +129,20 @@ function form_open_multipart($action = '', $attributes = array(), $hidden = arra
* @param bool
* @return string
*/
- function form_hidden($name, $value = '', $recursing = FALSE, $extra = '')
+ function form_hidden($name, $value = '', $extra = '', $recursing = FALSE)
{
static $form;
- if(strlen($extra))
+ if (is_array($extra))
+ {
+ $extra_string = '';
+ foreach ($extra as $key => $val)
+ {
+ $extra_string .= ' '.$key.'="'.$val.'"';
+ }
+ $extra = $extra_string;
+ }
+ elseif($extra != '')
$extra = ' '.$extra;
if ($recursing === FALSE)
@@ -145,7 +154,7 @@ function form_hidden($name, $value = '', $recursing = FALSE, $extra = '')
{
foreach ($name as $key => $val)
{
- form_hidden($key, $val, TRUE, $extra);
+ form_hidden($key, $val, $extra, TRUE);
}
return $form;
}
@@ -159,7 +168,7 @@ function form_hidden($name, $value = '', $recursing = FALSE, $extra = '')
foreach ($value as $k => $v)
{
$k = is_int($k) ? '' : $k;
- form_hidden($name.'['.$k.']', $v, TRUE, $extra);
+ form_hidden($name.'['.$k.']', $v, $extra, TRUE);
}
}
View
1  user_guide_src/source/changelog.rst
@@ -82,6 +82,7 @@ Release Date: Not Released
- Added an optional paramater to ``delete_files()`` to enable it to skip deleting files such as .htaccess and index.html.
- ``read_file()`` is now a deprecated alias of ``file_get_contents()``.
- :doc:`Security Helper <helpers/security_helper>` function ``strip_image_tags()`` is now an alias for the same method in the :doc:`Security Library <libraries/security>`.
+ - :doc:`Form Helper <helpers/form_helper>` function ``form_hidden()`` added an optional parameter to add attributes.
- Database
View
17 user_guide_src/source/helpers/form_helper.rst
@@ -148,6 +148,23 @@ If you want to create hidden input fields with extra attributes
<input type="hidden" name="email" value="john@example.com" id="hiddenemail" class="hiddenemail" />
*/
+or:
+
+::
+
+ $data = array(
+ 'id'          => 'hiddenemail',
+ 'class'       => 'hiddenemail'
+ );
+
+ echo form_hidden('email', 'john@example.com', $data);
+
+ /*
+ Would produce:
+
+ <input type="hidden" name="email" value="john@example.com" id="hiddenemail" class="hiddenemail" />
+ */
+
form_input()
============
Please sign in to comment.
Something went wrong with that request. Please try again.