Is there any easy way to get HTML5 Form elements into a Zend Form? createElement('tel','phone'); just doesn't work because zend doesn't support html5 form elements yet it seems... you can't override the type attribute either after it's been created.
E.G. I need input type="tel/email/date/number" etc on my zend form.
Benno,
Here is what I did to get Glitch to work: (Zend Framework 1.11)
in my Controller init() function
//someController extends Zend_Controller_Action
Then in my element creation, I simply override the type with attrib('type','email')
Without setting the view helpers, the input changes to Text.
Thanks!
Nevermind, I found this article: http://www.enrise.com/2010/12/html5-zend-framework-form-elements/. I just had to copy his code into my MVC architecture and it works now. Except I had to put $this->setAttrib('type','number') for example in Number.php, because it doesn't add the option unless its set in the controller, which is a bit stupid because I was creating a new Glitch_Form_Element_Text_Number or whatever o_O.
I've created a writeup that shows how to best use the Enrise HTML5 form elements, reiterating the fact that you need specify the HTML5 doctype.
Since there's no "out of box" solution, i wrote it my self and made a composer package for easy distribution. If you use composer, you can use it https://github.com/Alez/html5input
php $formElement->setAttrib('type', 'email')
. And that's the only difference between it and Zend_Form_Element_Text, you can treat it as simple text element.Example code:
Here is what I did to solve for XML5 elements.
First I created a custom form element on: library/Custom/Form/Element/Html5.php
Then I created a custom view helper on: library/Custom/View/Helper/FormHtml5.php
Then in the Form I added this:
Do not forget to add this line to your application.ini file in case you have not done so:
I hope it helps somebody.