summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--system/helpers/form_helper.php27
-rw-r--r--user_guide/changelog.html1
-rw-r--r--user_guide/helpers/form_helper.html49
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 />
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'name'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=> 'newsletter',<br />
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'id'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=> 'newsletter',<br />
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'value'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=> 'accept',<br />
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'checked'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=> TRUE,<br />
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'style'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; => 'margin:10px',<br />
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;);<br />
+&nbsp;&nbsp;&nbsp;&nbsp;'name'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=> 'newsletter',<br />
+&nbsp;&nbsp;&nbsp;&nbsp;'id'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=> 'newsletter',<br />
+&nbsp;&nbsp;&nbsp;&nbsp;'value'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=> 'accept',<br />
+&nbsp;&nbsp;&nbsp;&nbsp;'checked'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=> TRUE,<br />
+&nbsp;&nbsp;&nbsp;&nbsp;'style'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; => 'margin:10px',<br />
+&nbsp;&nbsp;&nbsp;&nbsp;);<br />
<br />
echo form_checkbox($data);<br />
<br />
@@ -331,8 +331,8 @@ fourth parameter:</p>
&lt;label id=&quot;username&quot;&gt;What is your Name&lt;/label&gt;</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' =&gt; 'mycustomclass',<br />
- 'style' =&gt; 'color: #000;',<br />
+&nbsp;&nbsp;&nbsp;&nbsp;'class' =&gt; 'mycustomclass',<br />
+&nbsp;&nbsp;&nbsp;&nbsp;'style' =&gt; '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 />
+&lt;button name="name" type="submit"&gt;Content&lt;/button&gt;
+</code>
+
+Or you can pass an associative array containing any data you wish your form to contain:
+<code>
+$data = array(<br />
+&nbsp;&nbsp;&nbsp;&nbsp;‘name’ => ‘button’,<br />
+&nbsp;&nbsp;&nbsp;&nbsp;‘id’ => ‘button’,<br />
+&nbsp;&nbsp;&nbsp;&nbsp;‘value’ => ‘true’,<br />
+&nbsp;&nbsp;&nbsp;&nbsp;‘type’ => ‘reset’,<br />
+&nbsp;&nbsp;&nbsp;&nbsp;‘content’ => ‘Reset’<br />
+);<br />
+<br />
+echo form_button($data);<br />
+<br />
+// Would produce:<br />
+&lt;button name="button" id="button" value="true" type="reset"&gt;Reset&lt;/button&gt;
+</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 &lt;/form> tag. The only advantage to using this function is it permits you to pass data to it