Symfony 4 - 选项“invalid_message”不存在

问题描述 投票:1回答:1

我使用Symfony 4.1,我尝试简单使用表单生成器:

    $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,
        ))

我收到了错误:

选项“invalid_message”不存在。定义的选项是....

我没有找到任何关于它的信息,我只是试图从Symfony Doc复制这个例子:https://symfony.com/doc/current/reference/forms/types/repeated.html

我需要导入一些东西吗?

symfony symfony4
1个回答
4
投票

invalid_message选项属于FormTypeValidatorExtension,当ValidatorExtension组件可用时由Validator加载。

您需要安装此组件以启用验证器选项:

composer require symfony/validator
© www.soinside.com 2019 - 2024. All rights reserved.