我想补充'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',
...
尝试注册像下面验证约束:
$builder
->add('name', TextType::class, [ 'label' => 'Name' ])
->add('email', EmailType::class, [
'label' => 'Email',
'constraints' => array(
new Email(array('strict'=>true)),
)
)
除了增加'strict' => true
到Email
的约束选项,也有在Symfony框架的配置,使其能够在默认情况下所有Email
约束的设置。见strict_email
configuration in the Symfony docs v3.4
为symfony1.2> = 4.1的配置选项strict_email
已弃用so use email_validation_mode
instead