Validating symfony2 forms with extra fields

symfony

Solution

To get Symfony2 accept additional data, add the additional fields to your form builder, and set their `property_path` option to false:

Example:

$builder
    ->add('my_additional_field', 'checkbox', array(
        'mapped' => false,
    ));

You don't need to drop the keys before binding the data, they'll be ignored anyway.

Problem

I'm working on a symfony2 backend for a backbone.js application. I have my model and form. However, backbone.js sends some additional properties to the REST API when it's creating/updating a model and I'm struggling to get the form to validate. How can I get a form in symfony2 to accept additional data, or how can I drop particular keys before binding data to a form?

Original source