Symfony2:摆脱“这种形式不应该包含额外的领域” [英] Symfony2: get rid of "This form should not contain extra fields"
问题描述
我已经在表单中添加了第二个提交按钮,现在Symfony2对此抱怨:此表单不应包含额外的字段
I have added a second submit button to my form, now Symfony2 complains about it: "This form should not contain extra fields"
尽管我在(
Although I added this option in the formtype:
public function getDefaultOptions(array $options)
{
return array(
'csrf_protection' => false,
);
}
有什么想法?
Any ideas?
推荐答案
你可以肯定有多个提交按钮。确保按钮与其他表单字段不在同一个数组中。
You can most certainly have multiple submit buttons. Make sure the button is not in the same array as the other form fields.
例如,如果您的表单字段的名称 FormType [field_name]
,你不能有 FormType [submit_btn]
作为按钮的名字,你必须选择一个不同的名字。
So, for example, if your form fields have a name FormType[field_name]
, you can't have FormType[submit_btn]
as the name of the button and you must choose a different one.
您的控制器可以根据按下的按钮采取不同的行为。如果您的提交按钮被命名为 submit_1
和 submit_2
,您可以使用类似于
Your controller can act differently depending on the button pressed. If your submit buttons are named submit_1
and submit_2
you can have something similar to
if($this->getRequest()->request->has('submit_1')) {
// do stuff
} else {
// do other stuff
}
这篇关于Symfony2:摆脱“这种形式不应该包含额外的领域”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!