I have built a registration form where I want to validate fields in it.
In my RegistrationFormType I have following code:
public function getDefaultOptions(array $options)
{
$collectionConstraint = new Collection(array(
'email' => new Collection(array(
new NotBlank(),
new Email(array('message' => 'Invalid email addressadsfa')),
)),
'username' => new Email(array('message' => 'arg Invalid email addressadsfa')),
'code' => new MaxLength(array('limit'=>20)),
'plainPassword' => new MaxLength(array('limit'=>20)),
));
return array(
'csrf_protection' => false,
'validation_constraint' => $collectionConstraint,
);
}
Problem is: The email validation does not work. What am I doing wrong?
You don’t need to make the email entry a Collection, just use a simple array. So: