0

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).

Community
  • 1
  • 1
eav
  • 2,123
  • 7
  • 25
  • 34

1 Answers1

0

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.

mpm
  • 20,148
  • 7
  • 50
  • 55
  • Okay, thanks for your answer. My 5 cent's to your trick: It's okay, but I'm not a fan of these tricks... You'll have a call to your webserver anyway, the advantage of html5 form-validation would have been making less calls to webserver... but it's fancy too. I think I don't want to use javascript validation at the moment.. – eav Mar 05 '13 at 07:17