M
M
Messi2019-05-25 16:06:41
symfony
Messi, 2019-05-25 16:06:41

How to display an error message?

Good afternoon! Couldn't figure out how to simply display an error when validating a form? Please tell me
there is a form

public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('name', TextType::class, [
            'constraints' => [
                new NotBlank(),
                new Length(
                    [
                        'min' => 2,
                        'max' => 255,
                    ]
                ),
            ],
        ]);
    }

And here if there are errors in the form, then output JsonResponse with the error text, $form->getErrors() returns empty.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
kosarinin, 2019-05-26
@kosarinin

https://stackoverflow.com/questions/24556121/how-t...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question