Created
February 8, 2013 23:29
-
-
Save unisys12/4742824 to your computer and use it in GitHub Desktop.
Codeigniter MY_form_helper.php - Adds some HTML5 Form Input Types that are not currently included. To use, just copy this file into your "application/helpers" folder while keeping the same name... MY_form_helper.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); | |
/** | |
* CodeIgniter HTML5 Form Helpers | |
* | |
* @package CodeIgniter | |
* @subpackage HTML5 Form Helpers | |
* @category Helpers | |
* @author Phillip Jackson | |
*/ | |
// ------------------------------------------------------------------------ | |
/** | |
* Date Field | |
* | |
* @access public | |
* @param mixed | |
* @param string | |
* @param string | |
* @param string | |
* @return string | |
*/ | |
if ( ! function_exists('form_date')) | |
{ | |
function form_date($data = '', $value = '', $extra = '') | |
{ | |
$defaults = array( | |
'type' => 'date', | |
'name' => (( ! is_array($data)) ? $data : ''), | |
'value' => $value | |
); | |
return "<input "._parse_form_attributes($data, $defaults).$extra." />"; | |
} | |
} | |
/** | |
* Email Field | |
* | |
* @access public | |
* @param mixed | |
* @param string | |
* @param string | |
* @param string | |
* @return string | |
*/ | |
if ( ! function_exists('form_email')) | |
{ | |
function form_email($data = '', $value = '', $placeholder = '', $extra = '') | |
{ | |
$defaults = array( | |
'type' => 'email', | |
'name' => (( ! is_array($data)) ? $data : ''), | |
'value' => $value, | |
'placeholder' => $placeholder | |
); | |
return "<input "._parse_form_attributes($data, $defaults).$extra." />"; | |
} | |
} | |
/** | |
* Number Field | |
* | |
* @access public | |
* @param mixed | |
* @param int | |
* @param int | |
* @param int | |
* @return int | |
*/ | |
if( ! function_exists('form_number')) | |
{ | |
function form_number($data = '', $value = '', $min = '', $max = '', $step = '', $extra = '') | |
{ | |
$defaults = array( | |
'type' => 'number', | |
'name' => (( ! is_array($data)) ? $data : ''), | |
'value' => $value, | |
'min' => $min, | |
'max' => $max, | |
'step' => $step | |
); | |
return "<input " . _parse_form_attributes($data, $defaults) . $extra . "/>"; | |
} | |
} | |
/** | |
* Range Field | |
* | |
* @access public | |
* @param mixed | |
* @param int | |
* @param int | |
* @param int | |
* @return int | |
*/ | |
if( ! function_exists('form_range')) | |
{ | |
function form_range($data = '', $value = '', $min = '', $max = '', $step = '', $extra = '') | |
{ | |
$defaults = array( | |
'type' => 'range', | |
'name' => (( ! is_array($data)) ? $data : ''), | |
'value' => $value, | |
'min' => $min, | |
'max' => $max, | |
'step' => $step | |
); | |
return "<input " . _parse_form_attributes($data, $defaults) . $extra . "/>"; | |
} | |
} | |
/** | |
* File Upload Field | |
* | |
* @access public | |
* @param mixed | |
* @param string | |
* @param string | |
* @return string | |
*/ | |
if ( ! function_exists('form_file')) | |
{ | |
function form_file($data = '', $value = '', $extra = '') | |
{ | |
$defaults = array('type' => 'file', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); | |
return "<input "._parse_form_attributes($data, $defaults).$extra." />"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment