D
D
Dmitry2019-02-28 05:39:01
symfony
Dmitry, 2019-02-28 05:39:01

Why does the error "This value should be of type array." occur?

The form has a "categories" field:

->add('categories', EntityType::class, [
    'choices' => $categories,
    'choice_label' => function (Category $category = null) {
        return null !== $category ? str_repeat('--', $category->getLevel()).' '.$category->getTitle() : '';
    },
    'choice_value' => function (Category $category = null) {
        return null !== $category ? $category->getId() : '';
    },
    'class' => Category::class,
    'constraints' => [
        new Assert\Choice([
            'choices' => $categories,
            'multipleMessage' => 'Выберите разделы из предложенного списка.',
            'multiple' => true,
        ]),
    ],
    'label' => 'Разделы',
    'multiple' => true,
 ])

After submitting the form for the field "categories" I get the error "This value should be of type array.". In the controller I check the type:
if ($form->isSubmitted()) {
    echo gettype($_POST['categories']); // Выводит "array"
}

What could be the reason?
Thank you all in advance.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question