我想在表单构建中将'strict' => true
添加到电子邮件验证输入中
https://symfony.com/doc/3.3/reference/constraints/Email.html#strict
为什么呢?因为普通电子邮件验证允许无效的电子邮件。 test@test
通过了!
我试过,但我收到错误(The option "strict" does not exist. Defined options are: "action", "allow_extra_fields", "attr", ... )
这样的代码:
public function buildForm(FormBuilderInterface $builder, array $options) :void
{
$builder
->add('name', TextType::class, [ 'label' => 'Name' ])
->add('email', EmailType::class, [
'label' => 'Email',
'strict' => true ] <<<<< not work
)
->add('subject', ChoiceType::class, [ 'label' => 'Subject',
...
答案 0 :(得分:2)
尝试注册以下验证限制:
$builder
->add('name', TextType::class, [ 'label' => 'Name' ])
->add('email', EmailType::class, [
'label' => 'Email',
'constraints' => array(
new Email(array('strict'=>true)),
)
)
答案 1 :(得分:0)
除了将'strict' => true
添加到Email
约束选项之外,Symfony框架配置中还存在一个设置,以默认情况下为所有Email
约束启用它。参见strict_email
configuration in the Symfony docs v3.4
对于Symfony> = 4.1,配置选项strict_email
已弃用so use email_validation_mode
instead