Validation symfony2验证组-只有一个组有效
这是我的表格:Validation symfony2验证组-只有一个组有效,validation,symfony,Validation,Symfony,这是我的表格: $forumuser = new Forumuser(); $passwordform = $this->createFormBuilder($forumuser, array('validation_groups' => array('userSettings'))) ->add('passwordold', 'password', array('attr' => array('autocomplete' =>
$forumuser = new Forumuser();
$passwordform = $this->createFormBuilder($forumuser, array('validation_groups' => array('userSettings')))
->add('passwordold', 'password', array('attr' => array('autocomplete' => 'off'), 'required' => false, 'error_bubbling' => true, 'property_path' => false))
->add('password', 'repeated', array( 'type' => 'password',
'invalid_message' => 'user.myprofile.password.repeat',
'options' => array('attr' => array('autocomplete' => 'off'), 'required' => false, 'error_bubbling' => true)
)
)
->getForm();
这是ForumUser.class中带有validationannotations的属性:
/**
* @var string $password
*
* @ORM\Column(name="password", type="string", length=200, nullable=false)
* @Assert\NotBlank(message="forumuser.password.notblank", groups={"userRegister", "userSettings"})
* @Assert\MinLength(limit="4", message="forumuser.password.minlength", groups={"userRegister", "userSettings"})
*/
private $password;
我想使用组userSettings,但绑定后$passwordform->getErrors为空。当我使用userRegister组时,所有其他属性都会被验证。这意味着,无论我做什么,密码属性都不会被验证
有人知道我做错了什么吗?
多谢各位
You have to define on form type , diiferent group name like this
public function getDefaultOptions(array $options)
{
return array(
'data_class' => '',
'cascade_validation' => true,
'validation_groups' => array('user_settings'),
);
}
和另一个一样