admin管理员组文章数量:1289565
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..
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..
-
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. :) – Vivin Paliath 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 :) – Leto Commented Dec 4, 2012 at 8:25
2 Answers
Reset to default 7Symfony 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
This is new Symfony 2 bundle which provide implementation of client side validation for Symfony Types (forms) https://github./formapro/JsFormValidatorBundle
(This bundle is still being maintained and seems to have support for Symfony 4)
本文标签: How to validate Symfony 2 form on client side (javascript)Stack Overflow
版权声明:本文标题:How to validate Symfony 2 form on client side (javascript) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741469229a2380499.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论