将RepeatedType验证错误附加到字段,而不是形成

时间:2016-04-21 09:29:23

标签: php symfony symfony-forms

我有FormBuilder

$builder
            ->add(
                'token',
                Type\TextType::class,
                array(
                    'required' => true,
                    'trim' => true,
                    'attr' => array(),
                    'constraints' => array(new Assert\NotBlank(array('message' => 'password.notBlank')))
                )
            )
            ->add(
                'password',
                Type\RepeatedType::class,
                array(
                    'type' => Type\PasswordType::class,
                    'required' => true,
                    'invalid_message' => 'password.notMatch',
                    'constraints' => array(
                        new Assert\NotBlank(array('message' => 'password.notBlank')),
                        new Assert\Length(
                            array(
                                'min' => 8,
                                'max' => 40,
                                'minMessage' => 'password.lengthMin',
                                'maxMessage' => 'password.lengthMax',
                            )
                        ),
                    )
                )
            );

问题是token字段附加到特定字段,因此我可以通过以下方式获取错误对象:

 foreach ($form->all() as $child) {
            foreach ($child->getErrors() as $key => $error) ...

但是password附加到表单本身,所以我唯一能得到错误的方法是:

$errors = $form->getErrors(true, false);

它没有给我任何字段描述信息..我怎样才能覆盖这种行为?

0 个答案:

没有答案