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

前端 未结 5 687
忘了有多久
忘了有多久 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:51

    If you are adding a single SubmitType button or similar, you use the solution Chausser indicated

    $entity = new Task();
    $form = $this->createForm(new TaskType(), $entity)->add('submit','SubmitType::class');
    

    However, in case you are using a CollectionType and embedding a set of sub forms, you need to include 'allow_add' => true in your parameters for that type. For example, in your EntityType form builder:

    $builder->add('subEntities', CollectionType::class, array(
                    'entry_type' => SubEntityType::class,
                    'entry_options' => array('label' => false),
                    'allow_add' => true,
                ))
    

    Make sure you do that for all levels of embedding if you have multiple levels.

提交回复
热议问题