简体   繁体   中英

How to validate Symfony 2 form on client side (javascript)

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

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

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)

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM