3

I need to post some data to my Symfony form and I use submit() method for this.

But when request contains some extra data, I got error:

"This form should not contain extra fields"

Is it possible to let form miss the extra data using form configuration ?

Maybe another way for doing this exists?

Notice: I need submit() method, not handleRequest() because I post my data through cross-domain ajax request, so form cannot be submitted this way. Reason: isValid() return false, because isSubmitted() return false.

P.S. Of course, I can create service that will be handle my request before passing it to the form, but maybe more elegant way exists.

Sergio Ivanuzzo
  • 1,820
  • 4
  • 29
  • 59

1 Answers1

12

In your Form Type:

    /**
     * @param OptionsResolver $resolver
     */
    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'AppBundle\Entity\YourEntity',
            'translation_domain' => strtolower('entity_translation_domain'),
            'allow_extra_fields' => true,
        ));
    }

The allow_extra_fields will enable your form to receive the extra data

luchaninov
  • 6,792
  • 6
  • 60
  • 75
Victor Sanchez
  • 960
  • 2
  • 12
  • 26