验证带有额外字段的 symfony2 表单 [英] Validating symfony2 forms with extra fields
问题描述
我正在为一个backbone.js 应用程序开发一个symfony2 后端.我有我的模型和表格.
但是,backbone.js 在创建/更新模型时会向 REST API 发送一些额外的属性,而我正在努力验证表单.
如何在 symfony2 中获取表单以接受其他数据,或者如何在将数据绑定到表单之前删除特定键?
要让 Symfony2 接受附加数据,请将附加字段添加到您的表单构建器中,并将它们的 property_path
选项设置为 false:>
示例:
$builder->add('my_additional_field', 'checkbox', array('映射' =>错误的,));
在绑定数据之前不需要删除键,它们无论如何都会被忽略.
I'm working on a symfony2 backend for a backbone.js application. I have my model and form.
However, backbone.js sends some additional properties to the REST API when it's creating/updating a model and I'm struggling to get the form to validate.
How can I get a form in symfony2 to accept additional data, or how can I drop particular keys before binding data to a form?
To get Symfony2 accept additional data, add the additional fields to your form builder, and set their property_path
option to false:
Example:
$builder
->add('my_additional_field', 'checkbox', array(
'mapped' => false,
));
You don't need to drop the keys before binding the data, they'll be ignored anyway.
这篇关于验证带有额外字段的 symfony2 表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!