In Codeigniter, through the documentation for its latest version 2.2.0, there is none helper for forms that generate fields for new types introduced with HTML5.
However, since it is very necessary nowadays, others have already experienced this problem and have created solutions.
An example can be found in the Codeigniter forum with the name Extended form helper to support HTML5 form Elements (English) which follows below:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* Common Input Field
*
* @access public
* @param string
* @param mixed
* @param string
* @param string
* @return string
*/
if ( ! function_exists('form_common'))
{
function form_common($type = 'text', $data = '', $value = '', $extra = '')
{
$defaults = array('type' => $type, 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value);
return "<input "._parse_form_attributes($data, $defaults).$extra." />";
}
}
/**
* Email Input Field
*
* @access public
* @param mixed
* @param string
* @param string
* @return string
*/
if ( ! function_exists('form_email'))
{
function form_email($data = '', $value = '', $extra = '')
{
return form_common($type = 'email', $data = '', $value = '', $extra = '');
}
}
/**
* Url Input Field
*
* @access public
* @param mixed
* @param string
* @param string
* @return string
*/
if ( ! function_exists('form_url'))
{
function form_url($data = '', $value = '', $extra = '')
{
return form_common($type = 'url', $data = '', $value = '', $extra = '');
}
}
/**
* Number Input Field
*
* @access public
* @param mixed
* @param string
* @param string
* @return string
*/
if ( ! function_exists('form_number'))
{
function form_number($data = '', $value = '', $extra = '')
{
return form_common($type = 'number', $data = '', $value = '', $extra = '');
}
}
/**
* Number Input Field
*
* @access public
* @param mixed
* @param string
* @param string
* @return string
*/
if ( ! function_exists('form_range'))
{
function form_range($data = '', $value = '', $extra = '')
{
return form_common($type = 'range', $data = '', $value = '', $extra = '');
}
}
/* End of file MY_form_helper.php */
/* Location: ./application/helpers/MY_form_helper.php */
For your particular case in order to create a input[type=data]
you should add to the file above:
/**
* Date Input Field
*
* @access public
* @param mixed
* @param string
* @param string
* @return string
*/
if ( ! function_exists('form_date'))
{
function form_date($data = '', $value = '', $extra = '')
{
return form_common($type = 'date', $data = '', $value = '', $extra = '');
}
}
Thanks for the return! Thanks!
– Saymon CAO