Symfony2 invalid form without errors

前端 未结 11 832
孤独总比滥情好
孤独总比滥情好 2020-12-01 01:46

I\'ve got a problem with a Symfony2 generated CRUD form. (With MongoDB Documents, but I do not think that this is related)

In my controller\'s createAction() method,

11条回答
  •  青春惊慌失措
    2020-12-01 02:16

    I’ve just got the same problem. For me, the form was not valid, but I could not get any errors by using $form->getErrors() or $form->getErrorsAsString(). I later found I forgot to pass the CSRF token to the form so it won’t be submitted, and $form->handleRequest($request) did nothing (no validation). As I saw @pit's answer, I tried to use

    $form->submit($request);
    
    $form->getErrorsAsString();
    

    it returned an error:

    ERROR: The CSRF token is invalid. Please try to resubmit the form.

    Here is some explanation in the documentation of Symfony2: http://symfony.com/doc/current/book/forms.html#handling-form-submissions

提交回复
热议问题