Php Symfony2表单未验证电子邮件和所需约束
我用Php Symfony2表单未验证电子邮件和所需约束,php,forms,symfony,constraints,symfony-forms,Php,Forms,Symfony,Constraints,Symfony Forms,我用Symfony2制作了这样一个表单: class UsuarioRegistroType extends AbstractType { public function BuildForm(FormBuilderInterface $builder, array $options) { $builder->add('email', 'email', array('label' => 'E-mail', 'required' => true)) .... 表
Symfony2
制作了这样一个表单:
class UsuarioRegistroType extends AbstractType {
public function BuildForm(FormBuilderInterface $builder, array $options) {
$builder->add('email', 'email', array('label' => 'E-mail', 'required' => true))
....
表单可以很好地工作,但是如果我写一些类似Email:asdf(不是Email address)的东西,我永远不会得到与此问题相关的错误。另外,如果我不写任何东西,我不会因为required constraint
而得到任何错误
你知道这个问题吗?
谢谢:)您刚刚使用了HTML5验证,许多barowser不支持此功能。与此旧版本不同的著名浏览器也不支持HTML5验证 我认为您应该使用注释从服务器端进行验证。我认为您了解注释,可以在实体类中使用注释。在enity类属性中,可以使用symfony2中的注释定义所需的验证规则 例如:
use Symfony\Component\Validator\Constraints as Assert;
class Author
{
/**
* @Assert\Email(
* message = "The email '{{ value }}' is not a valid email.",
* checkMX = true
* )
*/
protected $email;
}
Symfony2官方文档中的有用链接:您刚刚使用了HTML5验证,许多barowser不支持此功能。与此旧版本不同的著名浏览器也不支持HTML5验证 我认为您应该使用注释从服务器端进行验证。我认为您了解注释,可以在实体类中使用注释。在enity类属性中,可以使用symfony2中的注释定义所需的验证规则 例如:
use Symfony\Component\Validator\Constraints as Assert;
class Author
{
/**
* @Assert\Email(
* message = "The email '{{ value }}' is not a valid email.",
* checkMX = true
* )
*/
protected $email;
}
Symfony2官方文档中的有用链接:您刚刚使用了HTML5验证,许多barowser不支持此功能。与此旧版本不同的著名浏览器也不支持HTML5验证 我认为您应该使用注释从服务器端进行验证。我认为您了解注释,可以在实体类中使用注释。在enity类属性中,可以使用symfony2中的注释定义所需的验证规则 例如:
use Symfony\Component\Validator\Constraints as Assert;
class Author
{
/**
* @Assert\Email(
* message = "The email '{{ value }}' is not a valid email.",
* checkMX = true
* )
*/
protected $email;
}
Symfony2官方文档中的有用链接:您刚刚使用了HTML5验证,许多barowser不支持此功能。与此旧版本不同的著名浏览器也不支持HTML5验证 我认为您应该使用注释从服务器端进行验证。我认为您了解注释,可以在实体类中使用注释。在enity类属性中,可以使用symfony2中的注释定义所需的验证规则 例如:
use Symfony\Component\Validator\Constraints as Assert;
class Author
{
/**
* @Assert\Email(
* message = "The email '{{ value }}' is not a valid email.",
* checkMX = true
* )
*/
protected $email;
}
Symfony2官方文档中的有用链接:必需为true不验证任何内容。它只是在表单视图的字段上添加一个必需的类。是html5验证了这一点 尝试将其添加到UsuarioRegistroType类中:
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$collectionConstraint = new Collection(array(
'email' => array(
new NotBlank(array('message' => 'Email should not be blank.')),
new Email(array('message' => 'Invalid email address.'))
)
));
$resolver->setDefaults(array(
'constraints' => $collectionConstraint
));
}
不要忘记使用语句:
使用Symfony\Component\options解析器\options解析器接口
使用Symfony\Component\Validator\Constraints\Email
使用Symfony\Component\Validator\Constraints\NotBlank
使用Symfony\Component\Validator\Constraints\Collection 必需的true不验证任何内容。它只是在表单视图的字段上添加一个必需的类。是html5验证了这一点 尝试将其添加到UsuarioRegistroType类中:
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$collectionConstraint = new Collection(array(
'email' => array(
new NotBlank(array('message' => 'Email should not be blank.')),
new Email(array('message' => 'Invalid email address.'))
)
));
$resolver->setDefaults(array(
'constraints' => $collectionConstraint
));
}
不要忘记使用语句:
使用Symfony\Component\options解析器\options解析器接口
使用Symfony\Component\Validator\Constraints\Email
使用Symfony\Component\Validator\Constraints\NotBlank
使用Symfony\Component\Validator\Constraints\Collection 必需的true不验证任何内容。它只是在表单视图的字段上添加一个必需的类。是html5验证了这一点 尝试将其添加到UsuarioRegistroType类中:
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$collectionConstraint = new Collection(array(
'email' => array(
new NotBlank(array('message' => 'Email should not be blank.')),
new Email(array('message' => 'Invalid email address.'))
)
));
$resolver->setDefaults(array(
'constraints' => $collectionConstraint
));
}
不要忘记使用语句:
使用Symfony\Component\options解析器\options解析器接口
使用Symfony\Component\Validator\Constraints\Email
使用Symfony\Component\Validator\Constraints\NotBlank
使用Symfony\Component\Validator\Constraints\Collection 必需的true不验证任何内容。它只是在表单视图的字段上添加一个必需的类。是html5验证了这一点 尝试将其添加到UsuarioRegistroType类中:
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$collectionConstraint = new Collection(array(
'email' => array(
new NotBlank(array('message' => 'Email should not be blank.')),
new Email(array('message' => 'Invalid email address.'))
)
));
$resolver->setDefaults(array(
'constraints' => $collectionConstraint
));
}
不要忘记使用语句:
使用Symfony\Component\options解析器\options解析器接口
使用Symfony\Component\Validator\Constraints\Email
使用Symfony\Component\Validator\Constraints\NotBlank
使用Symfony\Component\Validator\Constraints\Collection 电子邮件类型和所需标志取决于浏览器。使用chrome运行表单,它将按预期工作。您需要添加服务器端验证,以使其按需要工作。请参阅本书中有关表单验证的部分:电子邮件类型和所需标志取决于浏览器。使用chrome运行表单,它将按预期工作。您需要添加服务器端验证,以使其按需要工作。请参阅本书中有关表单验证的部分:电子邮件类型和所需标志取决于浏览器。使用chrome运行表单,它将按预期工作。您需要添加服务器端验证,以使其按需要工作。请参阅本书中有关表单验证的部分:电子邮件类型和所需标志取决于浏览器。使用chrome运行表单,它将按预期工作。您需要添加服务器端验证,以使其按需要工作。请参阅本书中有关表单验证的部分: