HTML5 form elements in CakePHP formhelper

The latest release of my blog is completely made in HTML5 and CSS3. I love to work with the CakePHP formhelper since there's a lot of magic happening when used properly.

There's only one problem I found in the formhelper of CakePHP 1.3.6; I can't take the advantage of the HTML5 form types like 'email', 'url' or 'search'.

The legendary core-developers team of CakePHP fixed this issue in the CakePHP 2.0 branche, but since CakePHP 2.0 is still under heavy development and far from a stable release, I had to find a solution for the 1.3.6 formhelper.

The solution is simple but a bit hacky. But for the time being it will be fine.
You can find the hack in my github account.

After you applied the little formhelper hack you're able to do something like this:

<?php

;
?>

This will output something like:

There's ofcourse a lot more you can do with the new HTML5 form elements. For more HTML5 form magic please see something like: Fun with HTML5 Forms or A Form of Madness.

 

The solution

In cake/libs/views/helpers/form.php line 896 replace the case textarea and default with:

:
        ;
;
:
        ;
;

And finally create a new function before the function password:

/**
* Creates a default input widget, whose type is determined by $options['type'].
*
* @param string $fieldName Name of a field, in the form "Modelname.fieldname"
* @param array $options Array of HTML attributes.
* @return string A generated HTML input element
* @access public
*/
{
        $options
        ;
        )
        ;
}

 

Thanks to http://quentinhill.net/