6

I'm new to symfony 2 and i'm trying to build a standard form which should be validated by the server and by the navigator.

Server-side validation works fine with assertions like @Assert\... but i cannot find a way to get this working on client side.

After searching, i pointed out that Symfony 2 does not have a javascript library to manage this..

So my question is : What's the easiest way to do this ?

I know the possibility of using client side library like jQuery Validation plugin or something like Regula, but that would means that i have to duplicate my validations rules..

2
  • Hello Leto, I'm the author of Regula. I did something like what you're describing in Java, where I translated JSR-303 annotations to Regula constraints on the client-side. It might be possible to do something similar in PHP? I'm not too familiar with PHP, but does it provide a way to intercept the view before rendering? If so, you could have an interceptor that translates the @Assert into regula validation-constraints. Would take some work from your side, but it is a direction that you could go. :) Commented Dec 4, 2012 at 2:56
  • 1
    Hi, yeah i thought about it, but i'm just starting with SF2 and i have already pain with trivial things so i'm not yet good enough to do this job (and furthermore, i'm not working for myself, so it does not depend on me). That said, you did great job with regula :) Commented Dec 4, 2012 at 8:25

2 Answers 2

7

Symfony is a PHP framework, ie server-side application framework. It doesn't provide client-side validation unless you use HTML5 one with required attribute and other email type for input (that is still not very well implemented in browsers).

So you have to find your own solution and try to plug it in front of Symfony2 to make it as easy as possible... or find an existing bundle like APYJsFormValidationBundle

Sign up to request clarification or add additional context in comments.

4 Comments

Ok, i've tried APYJsFormValidationBundle but i get javascript errors.. Is there alternatives ?
The best alternative is to do it by yourself. No open source code is good enough to achieve it, as far as I know of course...
Sure, i'm trying this but couldn't get any basic tutorial to structure this, for example i may have differtents form that use the same validation rules, i don't want to hard code that each time. Validate form is something reccurent, why isn't there more explanation pn the subject ?
APYJsFormValidationBundle is is no longer maintained
0

This is new Symfony 2 bundle which provide implementation of client side validation for Symfony Types (forms) https://github.com/formapro/JsFormValidatorBundle

(This bundle is still being maintained and seems to have support for Symfony 4)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.