Symfony 2 form repeated validation in Entity with annotation

Posted by Sukhrob on Stack Overflow See other posts from Stack Overflow or by Sukhrob
Published on 2012-03-19T05:35:54Z Indexed on 2012/09/21 9:38 UTC
Read the original article Hit count: 126

Filed under:

My question is "How can I do form repeated validation in Entity with annotation?". I have an Account entity with (email, password and confirmPassword) attributes. When a new user registers a new account, he/she has to fill in email, password and confirmPassword fields. Obviously, password and confirmPassword fields must match. I saw an example of this validation with pure php (form builder) in Stachoverflow like below.

$builder->add('password', 'repeated', array(
    'type' => 'password',
    'first_name' => 'Password',
    'second_name' => 'Password confirmation',
    'invalid_message' => 'Passwords are not the same',
));

But, this is not what I want. I want this functionality with annotation in my Account entity. Maybe

* @Assert\Match(
*      matchField = "password",
*      message = "The password confirmation does not match password."
* )
protected $confirmPassword;

© Stack Overflow or respective owner

Related posts about symfony2