Search code examples
symfonysymfony4

Symfony 4 - The option "invalid_message" does not exist


I use Symfony 4.1, and I try a simple usage of form builder :

    $builder
        ->add('name', TextType::class)
        ->add('phone', TelType::class)
        ->add('password', RepeatedType::class, array(
            'type' => PasswordType::class,
            'invalid_message' => 'Passwords don\'t match',
            'options' => array('attr' => array('class' => 'password-field')),
            'required' => false,
            'first_options'  => array('label' => 'Password'),
            'second_options' => array('label' => 'Password confirmation'),
            'mapped' => false,
        ))

I got the error :

The option "invalid_message" does not exist. Defined options are ....

I don't find any informations on it, I just tried to copy the example from Symfony Doc : https://symfony.com/doc/current/reference/forms/types/repeated.html

Do I need to import something ?


Solution

  • The invalid_message option belong to FormTypeValidatorExtension which is loaded by ValidatorExtension when the Validator component is available.

    You need to install this component to enable the validator options:

    composer require symfony/validator