Additional fields Symfony 2

Im changing some fields through AJAX, and when I try to save the form, I get an error that Extra fields are not allowed.

How to change this validator property as validatorPass()in sf1.4?
Or is it possible to change the form to accept additional fields?

Im using SonataAdminBundle to create forms.

+5
source share
3 answers

You can remove additional fields from the request data before linking them to the form:

    // The JSON PUT data will include all attributes in the entity, even
    // those that are not updateable by the user and are not in the form.
    // We need to remove these extra fields or we will get a
    // "This form should not contain extra fields" Form Error
    $data = $request->request->all();
    $children = $form->all();
    $data = array_intersect_key($data, $children);
    $form->bind($data);
+20
source

In my case, the solution was really simple, just add allow_add in the field of your collection, below my example

        ->add('Details', 'collection', array(
            'type' => new DetailsType(),
            'allow_add' => true,
            'allow_delete' => true,
            'label' => ' '
        ))

http://symfony.com/doc/current/cookbook/form/form_collections.html

, , , . , , : . , allow_add .

+1
0
source

All Articles