A
A
Alexander Evgenievich2015-11-11 14:43:50
symfony
Alexander Evgenievich, 2015-11-11 14:43:50

Why doesn't the form validate when using the "collection" type with text values?

public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('description', 'text')
            ->add('coordinates', 'collection', array(
                'type' => 'text'
            ));

    }

    public function setDefaultOptions(OptionsResolverInterface $resolver){

        $resolver->setDefaults(array(
            'allow_extra_fields' => true,
            'csrf_protection' => false,
            'data_class' => '\AppBundle\Entity\Marker'
        ));

    }

I send:
$dataMarker = array(
                'description' => "asdasdada",
                'coordinates' => array(123123, 234234)
            );

            $form = $this->get('form.factory')->create(new MarkerType(), new Marker());
            $form->submit($dataMarker);

Returns "This form should not contain extra fields".
And if you use the text type instead of colleciton, and pass text to the coordinates field as well, then it normally passes without errors.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Evgenievich, 2015-11-11
@banderos120

It turned out that you need to specify "allow_extra_fields" directly in the field initialization array with the collection type:

->add('coordinates', 'collection', array(
                'type' => 'text',
                'allow_add' => true,
                'allow_extra_fields' => true
            ));

Only sherali there in general this error.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question