脚本宝典收集整理的这篇文章主要介绍了php – 在Symfony2中创建组合的客户端和服务器端验证,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
执行此操作的最佳方法是将验证约束传递给表单视图.
有了这些信息,就可以制作一个模板,将表单字段呈现为:
<div> <label for="form_email">E-Mail</label> <input id="form_email" tyPE="text" name="form[email]" value="" data-validation-constraints='{"NotBlank":{},"MinLength":{"limIT":6}}' /> </div>
然后JavaScript部分将找到所有< input>具有data-validation-constraints属性的元素,并为它们创建正确的验证.
要将验证约束传递给表单视图,我认为最好的方法是创建表单类型扩展.这就是我的问题:这是正确的方法吗?这怎么可能?
在片刻,我的表单类型扩展如下所示:
use Symfony\component\Form\FormInterface; use Symfony\Component\Form\FormView; use Symfony\Component\Form\FormBuilder; class FieldTypeExtension extends \Symfony\Component\Form\AbstractTypeExtension{ public function getExtendedType(){ return 'field'; } public function buildView(FormView $view,FormInterface $form) { // at this point i didn't find a way to get the // validation constraints out of the $form // the `getAllValidationConstraints` here is just an example $view->set('validation_constraints',$form->getAllValidationConstraints()); } }
以上是脚本宝典为你收集整理的php – 在Symfony2中创建组合的客户端和服务器端验证全部内容,希望文章能够帮你解决php – 在Symfony2中创建组合的客户端和服务器端验证所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。