根据多个约束验证表单字段
我已经构建了一个注册表单,我想验证其中的字段。 在我的 RegistrationFormType
中,我有以下代码:
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,
);
}
问题是:电子邮件验证不起作用。我做错了什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不需要将电子邮件条目设为集合,只需使用简单的数组即可。所以:
You don't need to make the email entry a Collection, just use a simple array. So: