Symfony2 Form, PATCH requests and handleRequest: Form is never valid

From Symfony 2.3 we can use (PR #7849) PATCH requests with the Form component to submit a part of the form which will override the form default values. This is really helpful moreover using FOSRestBundle and its listeners !

With this configuration, to make a user available to PATCH its profile using REST API, you simply have to write this few lines:

But the form is never valid…

In fact, you’ll never have a valid form if you let it as it’s. The problem is that the form is never submitted by the HttpFundationRequestHandler because the current request method (PATCH) isn’t a GET or POST, which are waited by the form (see L39).

Two solutions

You’ve 2 simple solutions, use the submit method, or set the method option on the form.

facebooktwittergoogle_plusredditpinterestlinkedinmail

3 thoughts on “Symfony2 Form, PATCH requests and handleRequest: Form is never valid”

  1. Hello,

    I have mixed the two solutions :
    $form = $this->createForm(FormType::class, $entity,[
    'method' => $request->getMethod()
    ]);

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">