Skip to content

Commit 09eee76

Browse files
committed
Added html5 form input and range types.
1 parent 6addf31 commit 09eee76

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed

system/helpers/form_helper.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,65 @@ function form_input($data = '', $value = '', $extra = '')
180180
}
181181
}
182182

183+
184+
// ------------------------------------------------------------------------
185+
186+
/**
187+
* Form Input Type
188+
*
189+
* Create an html5 input field.
190+
*
191+
* @access public
192+
* @param mixed string $type The input type or array of values
193+
* @param string $data The input name
194+
* @param string $value The input value
195+
* @param string $extra Any extra attributes
196+
*/
197+
if ( ! function_exists('form_input_type'))
198+
{
199+
function form_input_type($type = '', $data = '', $value = '', $extra = '')
200+
{
201+
$defaults = array(
202+
'type' => (( ! empty($type)) ? $type : 'text'),
203+
'name' => (( ! is_array($data)) ? $data : ''),
204+
'value' => $value
205+
);
206+
207+
return "<input "._parse_form_attributes($type, $defaults).$extra." />";
208+
}
209+
}
210+
211+
// ------------------------------------------------------------------------
212+
213+
/**
214+
* Form Input Range
215+
*
216+
* Create an html5 input range field.
217+
*
218+
* @access public
219+
* @param string $data The input name
220+
* @param string $min The min value
221+
* @param string $max The max value
222+
* @param string $step The step value
223+
* @param string $value The input value
224+
* @param string $extra Any extra attributes
225+
*/
226+
if ( ! function_exists('form_input_range'))
227+
{
228+
function form_input_range($data = '', $min = 0, $max = 0, $step = 0, $value = '', $extra = '')
229+
{
230+
$defaults = array(
231+
'type' => 'time',
232+
'name' => (( ! is_array($data)) ? $data : ''),
233+
'value' => $value
234+
);
235+
236+
$extra = 'min="'.$min.'" max="'.$max.'" step="'.$step.'" '.$extra;
237+
238+
return "<input "._parse_form_attributes($data, $defaults).$extra." />";
239+
}
240+
}
241+
183242
// ------------------------------------------------------------------------
184243

185244
/**

user_guide/changelog.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ <h2>Version 2.0.3</h2>
8282
<ul>
8383
<li>Added an optional third parameter to <samp>heading()</samp> which allows adding html attributes to the rendered heading tag.</li>
8484
<li class="reactor"><kbd>form_open()</kbd> now only adds a hidden (Cross-site Reference Forgery) protection field when the form's action is internal and is set to the post method. (Reactor #165)</li>
85+
<li class="reactor"><kbd>form_input_type()</kbd> added to the <a href="helpers/form_helper.html#form_input_type">form helper</a> to handle the majority of html5 input types.</li>
86+
<li class="reactor"><kbd>form_input_range()</kbd> added to the <a href="helpers/form_helper.html#form_input_range">form helper</a> to handle html5 range input types.</li>
8587
</ul>
8688
</li>
8789
<li>Libraries

user_guide/helpers/form_helper.html

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,33 @@ <h2>form_input()</h2>
177177
<br />
178178
echo form_input('username', 'johndoe', $js);</code>
179179

180+
<h2 id="form_input_type">form_input_type()</h2>
181+
182+
<p>This function is used to create most types of html5 input fields. You can minimally pass the field name and value in the first and second parameter:</p>
183+
184+
<code>echo form_input_type('tel', 'phone');</code>
185+
186+
Would produce:
187+
<code>&lt;input type=&quot;tel&quot; name=&quot;phone&quot; value=&quot;&quot; /&gt;</code>
188+
189+
It also two additional params:
190+
191+
<code>echo form_input_type('tel', 'phone', '8675309', 'id="phone"');</code>
192+
193+
Would produce:
194+
<code>&lt;input type=&quot;tel&quot; name=&quot;phone&quot; value=&quot;8675309&quot; id=&quot;phone&quot; /&gt;</code>
195+
196+
<h2 id="form_input_range">form_input_range()</h2>
197+
198+
<p>This function is used to create an html5 range field:</p>
199+
200+
<code>echo form_input_range('year', '2005', '2011', '1');</code>
201+
202+
Would produce:
203+
<code>&lt;input type=&quot;time&quot; name=&quot;year&quot; value=&quot;&quot; min=&quot;2005&quot; max=&quot;2011&quot; step=&quot;1&quot; /&gt;</code>
204+
205+
<p>The optional fifth and sixth parameters are a default value and a string of any extra attributes such as id, class, style.</p>
206+
180207
<h2>form_password()</h2>
181208

182209
<p>This function is identical in all respects to the <dfn>form_input()</dfn> function above

0 commit comments

Comments
 (0)