简体   繁体   English

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

[英]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.我是 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\\...这样的断言@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 之类的东西)的可能性,但这意味着我必须复制我的验证规则..

Symfony is a PHP framework, ie server-side application framework. Symfony 是一个 PHP 框架,即服务器端应用程序框架。 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).它不提供客户端验证,除非您使用具有required属性和其他email类型的 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这样的现有包

This is new Symfony 2 bundle which provide implementation of client side validation for Symfony Types (forms) https://github.com/formapro/JsFormValidatorBundle这是新的 Symfony 2 包,它为 Symfony 类型(表单)提供客户端验证的实现https://github.com/formapro/JsFormValidatorBundle

(This bundle is still being maintained and seems to have support for Symfony 4) (这个包仍在维护中,似乎支持 Symfony 4)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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