Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony 2 form extra fields

Im changing some fields via AJAX and when im trying to save a form i recive a error that Extra fields are not allowed.

How to change that validator property like validatorPass() in sf1.4 ?
Or its possible change to form to accept extra fields ?

Im using SonataAdminBundle to create forms.

like image 316
Pawel Avatar asked Jan 31 '12 11:01

Pawel


1 Answers

You could remove the extra fields from the request data before binding 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);
like image 162
rhunwicks Avatar answered Nov 15 '22 00:11

rhunwicks