如何在客户端验证Symfony 2表单(javascript)

时间:2021-08-21 07:23:08

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.

我是symfony 2的新手,我正在尝试构建一个应该由服务器和导航器验证的标准表单。

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

服务器端验证可以正常使用像@Assert \ ...这样的断言,但我找不到在客户端使用它的方法。

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

搜索后,我指出Symfony 2没有javascript库来管理这个..

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

我知道使用客户端库的可能性,如jQuery Validation插件或类似Regula,但这意味着我必须复制我的验证规则..

2 个解决方案

#1


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

Symfony是一个PHP框架,即服务器端应用程序框架。它不提供客户端验证,除非您使用具有必需属性和其他电子邮件类型的HTML5进行输入(在浏览器中仍然没有很好地实现)。

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

因此,您必须找到自己的解决方案并尝试将其插入Symfony2前面,以使其尽可能简单...或找到像APYJsFormValidationBundle这样的现有捆绑包

#2


0  

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

这是新的Symfony 2软件包,它为Symnfony类型(表单)提供客户端验证的实现https://github.com/formapro/JsFormValidatorBundle

#1


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

Symfony是一个PHP框架,即服务器端应用程序框架。它不提供客户端验证,除非您使用具有必需属性和其他电子邮件类型的HTML5进行输入(在浏览器中仍然没有很好地实现)。

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

因此,您必须找到自己的解决方案并尝试将其插入Symfony2前面,以使其尽可能简单...或找到像APYJsFormValidationBundle这样的现有捆绑包

#2


0  

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

这是新的Symfony 2软件包,它为Symnfony类型(表单)提供客户端验证的实现https://github.com/formapro/JsFormValidatorBundle