diff options
-rw-r--r-- | system/helpers/form_helper.php | 27 | ||||
-rw-r--r-- | user_guide/changelog.html | 1 | ||||
-rw-r--r-- | user_guide/helpers/form_helper.html | 49 |
3 files changed, 69 insertions, 8 deletions
diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 7c3b16ff1..db41cb5cd 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -387,6 +387,33 @@ if (! function_exists('form_reset')) // ------------------------------------------------------------------------
/**
+ * Form Button
+ *
+ * @access public
+ * @param mixed
+ * @param string
+ * @param string
+ * @return string
+ */
+if (! function_exists('form_button'))
+{
+ function form_button($data = '', $content = '', $extra = '')
+ {
+ $defaults = array('name' => (( ! is_array($data)) ? $data : ''), 'type' => 'submit');
+
+ if ( is_array($data) AND isset($data['content']))
+ {
+ $content = $data['content'];
+ unset($data['content']); // content is not an attribute
+ }
+
+ return "<button ".parse_form_attributes($data, $defaults).$extra.">".$content."</button>\n";
+ }
+}
+
+// ------------------------------------------------------------------------
+
+/**
* Form Label Tag
*
* @access public
diff --git a/user_guide/changelog.html b/user_guide/changelog.html index b8bbb330e..7ba6c3e7b 100644 --- a/user_guide/changelog.html +++ b/user_guide/changelog.html @@ -69,6 +69,7 @@ Change Log <ul>
<li>Added increased security for filename handling in the Upload library.</li>
<li>Added increased security for sessions for client-side data tampering.</li>
+ <li>Added <kbd>form_button()</kbd> in the <a href="helpers/form_helper.html">Form helper</a>.</li>
</ul>
</li>
<li>Helpers
diff --git a/user_guide/helpers/form_helper.html b/user_guide/helpers/form_helper.html index 95041e562..fa33e6a48 100644 --- a/user_guide/helpers/form_helper.html +++ b/user_guide/helpers/form_helper.html @@ -288,12 +288,12 @@ echo fieldset_close($string);<br /> <p>Similar to the other form functions in this helper, you can also pass an array of attributes to the function:</p>
<code>$data = array(<br />
- 'name' => 'newsletter',<br />
- 'id' => 'newsletter',<br />
- 'value' => 'accept',<br />
- 'checked' => TRUE,<br />
- 'style' => 'margin:10px',<br />
- );<br />
+ 'name' => 'newsletter',<br />
+ 'id' => 'newsletter',<br />
+ 'value' => 'accept',<br />
+ 'checked' => TRUE,<br />
+ 'style' => 'margin:10px',<br />
+ );<br />
<br />
echo form_checkbox($data);<br />
<br />
@@ -331,8 +331,8 @@ fourth parameter:</p> <label id="username">What is your Name</label></code>
<p>Similar to other functions, you can submit an associative array in the third parameter if you prefer to set additional attributes. </p>
<p><code>$attributes = array(<br />
- 'class' => 'mycustomclass',<br />
- 'style' => 'color: #000;',<br />
+ 'class' => 'mycustomclass',<br />
+ 'style' => 'color: #000;',<br />
);<br />
echo form_label('What is your Name', 'username', $attributes);<br />
<br />
@@ -342,6 +342,39 @@ fourth parameter:</p> <p>Lets you generate a standard reset button. Use is identical to <dfn>form_submit()</dfn>.</p>
+<h2>form_button()</h2>
+
+<p>Lets you generate a standard button element. You can minimally pass the button name and content in the first and second parameter:</p>
+<code>
+echo form_button(’name’,’content’);<br />
+<br />
+// Would produce<br />
+<button name="name" type="submit">Content</button>
+</code>
+
+Or you can pass an associative array containing any data you wish your form to contain:
+<code>
+$data = array(<br />
+ ‘name’ => ‘button’,<br />
+ ‘id’ => ‘button’,<br />
+ ‘value’ => ‘true’,<br />
+ ‘type’ => ‘reset’,<br />
+ ‘content’ => ‘Reset’<br />
+);<br />
+<br />
+echo form_button($data);<br />
+<br />
+// Would produce:<br />
+<button name="button" id="button" value="true" type="reset">Reset</button>
+</code>
+
+If you would like your form to contain some additional data, like JavaScript, you can pass it as a string in the third parameter:
+<code>
+$js = ‘onClick="some_function()"’;<br /><br />
+echo form_button(’mybutton’, ‘Click Me’, $js);
+</code>
+
+
<h2>form_close()</h2>
<p>Produces a closing </form> tag. The only advantage to using this function is it permits you to pass data to it
|