symfony2 FOSUserBundle自定义注册表单验证失败“请输入密码”

时间:2013-07-18 17:06:45

标签: forms validation symfony fosuserbundle

我已经定制了FOSUserBundle的注册表格,我已将其添加到我的BloggerBlogBu​​ndle中,但当我尝试提交注册表单时,它只是说“请输入密码”......

这是我的registrationFormType

public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder
        ->add('fname', null, array('label' => 'first name', 'translation_domain' => 'FOSUserBundle'))
        ->add('lname', null, array('label' => 'last name', 'translation_domain' => 'FOSUserBundle'))
        ->add('username', null, array('label' => 'form.username', 'translation_domain' => 'FOSUserBundle'))
        ->add('email', 'email', array('label' => 'form.email', 'translation_domain' => 'FOSUserBundle'))
        ->add('category','choice', array(
        'choices' => array(
            'sport' =>'sport',
            'news' => 'news',
            'ecommerce' => 'ecommerce',
        )))
        ->add('password', 'repeated', array(
            'type' => 'password',
            'options' => array('translation_domain' => 'FOSUserBundle'),
            'first_options' => array('label' => 'form.password'),
            'second_options' => array('label' => 'form.password_confirmation'),
            'invalid_message' => 'fos_user.password.mismatch',
        ))
    ;
}

1 个答案:

答案 0 :(得分:1)

请查看您尝试覆盖的FOSUserBundle中的original form

那里不存在字段password。字段名称为plainPassword

更改自定义表单中字段的名称以解决问题。