Symfony2.4 form 'This form should not contain extra fields' error

前端 未结 5 686
忘了有多久
忘了有多久 2020-12-10 12:17

I\'m trying to build app based on REST api ang AngularJS. I\'ve been following this tutorial http://npmasters.com/2012/11/25/Symfony2-Rest-FOSRestBundle.html but have to cha

5条回答
  •  心在旅途
    2020-12-10 12:47

    If you wanna disable fields validation, you must add

    public function setDefaultOptions(\Symfony\Component\OptionsResolver\OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'csrf_protection' => false,
            'validation_groups' => false,
        ));
    }
    

    And in buildForm method:

        public function buildForm(FormBuilderInterface $builder, array $options) {
            $builder->addEventListener(FormEvents::POST_SUBMIT, function ($event) {
                $event->stopPropagation();
            }, 900);
            $builder->add('field1','text')
                    ->add('field2','text')
                    .
                    .
                    .
        } 
    

    For more details: http://symfony.com/doc/current/cookbook/form/dynamic_form_modification.html#cookbook-dynamic-form-modification-suppressing-form-validation

提交回复
热议问题