Symfony2: handleRequest() is not submitting the form

14,542

Are you setting the method param when creating your $editForm?

$editForm = $this->createForm(new TaskType(), $task, array(
    'action' => $this->generateUrl('edit_task'),
    'method' => 'PUT',
));

$editForm->handleRequest($request);

Additionally you might need to set http_method_override in your config. http://symfony.com/doc/current/reference/configuration/framework.html#http-method-override

Share:
14,542
Marek
Author by

Marek

Updated on July 25, 2022

Comments

  • Marek
    Marek almost 2 years

    I have got strange problem with handleRequest method in Symfony 2.3.5.

    I am submitting form with handleRequest ($editForm->handleRequest($request)) and everything is working fine on dev. But on prod environment it is not working. I have debug everything and I found that it is not submitting this form.

    I have managed to get this working with changing

    $editForm->handleRequest($request)
    

    to

    $editForm->submit($request->request->get($editForm->getName()))
    

    But could someone tell me why handleRequest is not working for me just in prod environment?

    I have removed all cache.

    EDIT: I have also remind myself that it is working great on creating, but not on editing/updating.

  • timhc22
    timhc22 almost 10 years
    weird that you didn't have to do this with $form->submit. what a headache that caused
  • Jeremy Zerr
    Jeremy Zerr almost 10 years
    I had this same problem, but didn't actually have to add the 'action' into the options, I only had to add the 'method' => 'PUT'. My situation might be different as my project is only a REST API.
  • Leevi Graham
    Leevi Graham almost 10 years
    @JeremyZerr yeah if you're just building an API you'll never need to render a form on the front end and therefore not need action.