0
votes

Even when an element of Zend Framework has no setRequired() or has setRequired(false) called it is always rendered as <input ..... required="">

And seeing this code Chrome, Firefox and other newest versions of browsers while trying to validate the form before posting it, show the error message that the field is required (although it is not). It seems the browser detects the presence of the attribute required and does not care about its value (empty in this case).

Additionally, I tried <form novalidate="novalidate" ...> to ignore the browser validation but it did not work (anyway it would not be a good solution as one might still need to keep that browser side validation).

So, the question is how to make ->setRequired(true) to render required="required" and the lack of ->setRequired() or ->setRequired(false) not to render any attribute?

2
Please post your code. As far as I can tell ZF doesn't support the required attribute, so are you setting it manually using setAttrib()?Tim Fountain

2 Answers

1
votes

the ->setRequired(true) is only for the server side validation. to add the HTML5 required I use this

->setAttrib('required','true')

This will add required="true" which is not really necessary a simple required would be sufficient. But I never found a way to do that in Zend

0
votes

In the input tag "required" attribute is a HTML5 attribute,not sure that Zend supports that.

You can set required it easily by using "->setRequired(true)" where you are declaring form elements by extending zend_form.