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

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

    Its because when you are generating the form you are adding submit buttons but when you are validating them you are not. try:

    public function cpostAction(Request $request)
    {
        $entity = new Task();
        $form = $this->createForm(new TaskType(), $entity)->add('submit','submit');
        ...
    

    The submit button is technically a field even though symfony wont map it to an entity property by default. So when you generate the form with a submit button and then submit that form the form you generate in your validation controller action needs to also have a submit button.

提交回复
热议问题