title: Submit a Form using PUT instead of POST
body: <p>I have a controller which processes form submission from AJAX requests. I don't want to repeat myself, so I put the form processing code in a method:</p>
  
  <pre><code>// Should process POST request
  public function create(Request $request)
  {
      return $this-&gt;processEdit($request);
  }
  
  // Should process PUT request
  public function update($id, Request $request)
  {
      $entity = $this-&gt;findEntity($id); // custom method
  
      if (!$entity)
          return $this-&gt;myCustomErrorResponse();
  
      return $this-&gt;processEdit($request, $entity);
  }
  
  private function processEdit(Request $request, Entity $entity = null)
  {
      $form = $this-&gt;createForm('my_entity', $entity);
  
      $form-&gt;handleRequest($request);
  
      if ($form-&gt;isValid()) {
          // Do something
      } else {
          // Handle invalid form
      }
  
      return $response;
  }
  </code></pre>
  
  <p>I have the following two routes:</p>
  
  <pre><code>ajax_create:
      pattern: /
      defaults: { _controller: 'MyBundle:Ajax:create' }
      methods: [ POST ]
  
  ajax_update:
      pattern: /{id}
      defaults: { _controller: 'MyBundle:Ajax:update' }
      methods: [ PUT ]
      requirements:
          id: \d+
  </code></pre>
  
  <p>However, when I submit the form via AJAX, it will not accept <code>PUT</code> request and return form is not valid without any form error message. If I alter the controller code abit,</p>
  
  <pre><code>$form = $this-&gt;createForm('my_entity', $entity, array(
      'method' =&gt; 'PUT',
  ));
  </code></pre>
  
  <p>... it will process <code>PUT</code> request but not <code>POST</code> request.</p>
  
  <p>I wondered which part of Symfony2 does the HTTP method checking for a form so I tried to look for the answer in the source code, but I couldn't find a clue. Could any of you share your knowledge please?</p>
  
  <p>Another question, is there a way to bypass HTTP method checking? I'm currently passing <code>$method</code> to the method shown above.</p>
  
  <p>Thank you very much.</p>
  
  <hr>
  
  <p>Update:</p>
  
  <p>To make my question clearer, my Symfony2 application routes the request (both POST and PUT) to the correct controller method.</p>
  
  <p>I mentioned the altered code above, here it is:</p>
  
  <pre><code>// Should process POST request
  public function create(Request $request)
  {
      return $this-&gt;processEdit($request);
  }
  
  // Should process PUT request
  public function update($id, Request $request)
  {
      $entity = $this-&gt;findEntity($id); // custom method
  
      if (!$entity)
          return $this-&gt;myCustomErrorResponse();
  
      return $this-&gt;processEdit($request, 'PUT', $entity);
  }
  
  private function processEdit(Request $request, $method = 'POST', Entity $entity = null)
  {
      $form = $this-&gt;createForm('my_entity', $entity, array(
          'method' =&gt; $method,
      ));
  
      $form-&gt;handleRequest($request);
  
      if ($form-&gt;isValid()) {
          // Do something
      } else {
          // Handle invalid form
      }
  
      return $response;
  }
  </code></pre>