i want to add 'strict' => true
to email validation input in form building https://symfony.com/doc/3.3/reference/constraints/Email.html#strict
why? because normal email validation allow invalid emails ex. test@test
passed!
i tried but i get error (The option "strict" does not exist. Defined options are: "action", "allow_extra_fields", "attr", ... )
code like that:
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',
...
Try to register validation constraints like below:
$builder
->add('name', TextType::class, [ 'label' => 'Name' ])
->add('email', EmailType::class, [
'label' => 'Email',
'constraints' => array(
new Email(array('strict'=>true)),
)
)
In addition to adding 'strict' => true
to Email
the constraint options, there is also a setting in the Symfony framework config to enable it for all Email
constraints by default. See strict_email
configuration in the Symfony docs v3.4
For Symfony >=4.1 the configuration option strict_email
has been deprecated so use email_validation_mode
instead
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.