There is the great functionality of using html5 validation in symfony2 forms.
After searching a while in the internet, I found this great solution:
But this gives me allways only one validation-message
Would you please enter a valid email?
What about multiple validation-messages? Like it is described in the docs:
So I'm able to use either html5 form-validation with one message, or I'm able to use normal validations (like in the link) with multiple messages, but no client-side validation like html5 (Of course, I could implement some validation functions, but I'd prefer to use the built-in html5 functionality)
Edit: I did some research, It looks like this html5 form-validation has nothing to do with the symfony2 framework, is that correct? So basically without creating too much client-side code, I'm only able to make check for "required" (which is the original reason of this attribute).
Edit: I did some research, It looks like this html5 form-validation has nothing to do with the symfony2 framework, is that correct? So basically without creating too much client-side code, I'm only able to make check for "required" (which is the original reason of this attribute).
basically yes , you can add some attributes to your tags when you build your form builder->add("name","text",array("attr"=>array(" ... "
, and yes marking marking a field has required had a required attribute to your html tag. If you want to turn of the html5 validation you can use the novalidate attribute in the form tag , then use a client js library to do the work or whatever.
A trick i like to use is with js , on submit , send the form to the server as an ajax request , then get the new html rendered form as a response , so I get the awesomeness of symfony and javascript combined without the need of a js validation library. You just need to write the an on submit handler with some ajax.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.