我有一个简单的表格:
class SignInType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('_username', 'text');
$builder->add('_password', 'password');
$builder->add('Sign in', 'submit');
}
public function getName()
{
return 'sign_in';
}
}
我打电话给我的登录'动作:
public function signInAction()
{
$form = $this->createForm(new SignInType(), null,
[ 'action' => $this->generateUrl('my_project_account_sign_in_process') ]
);
但是,绑定POST请求会导致表单无效,错误为This form should not contain extra fields
。它似乎是导致问题的提交按钮 - 我该如何解决?
public function signInProcessAction(Request $request)
{
$doctrineManager = $this->getDoctrine()->getManager();
$form = $this->createForm(new SignInType());
$form->handleRequest($request);
...
答案 0 :(得分:1)
我通过删除按钮名称中的空格来修复此问题:
public function buildForm(FormBuilderInterface $builder, array $options)
{
...
$builder->add('Sign_in', 'submit');
}
答案 1 :(得分:0)
然后错误This form should not contain extra fields
肯定是由没有名字的表单引起的。 Symfony无法获取表单字段并尝试获取一些随机的其他元素吗?