我有一个简单的表格:

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);
    ...

===============>>#1 票数:1

我已通过删除按钮名称中的空格来解决此问题:

public function buildForm(FormBuilderInterface $builder, array $options)
{
    ...
    $builder->add('Sign_in', 'submit');
}

===============>>#2 票数:0

然后,错误“ This form should not contain extra fields肯定是由没有名称的表单引起的。 Symfony无法获取表单字段并尝试获取一些随机的其他元素?

  ask by Jonathan translate from so

未解决问题?本站智能推荐: