1

I have a form with PUT method

{{ form(formEdit, {'action': path('user_update',{'id':user.id}), 'method': 'PUT'}) }}

And My Action is

/**
     * Edits an existing User entity.
     *
     * @Route("/{id}", name="user_update")
     * @Method("PUT")
     * @Template("foo:User:update.html.twig")
     * @ParamConverter("User", class="foo:User")
     */
    public function updateAction(Request $request,User $user){
        $form = $this->createForm(new UserType(), $user);
        $form->handleRequest($request);
        if ($form->isValid()) {
            $em = $this->getDoctrine()->getManager();
            $em->persist($user);
            $em->flush();

            return $this->redirect($this->generateUrl('user',array('id' => $user->getId())));
        }


        return array(
            'formEdit' => $form->createView(),
            'user' => $user
        );
    }

My Twig

{{ form(formEdit, {'action': path('user_update',{'id':user.id}),'method':'PUT'}) }}

When I Submitted the form, I haven't any errors. If I Change PUT with POST, the form works. I tried with

    echo $request->getMethod();
    echo $form->getErrorsAsString();

and this is my output

PUT
name: No errors surname: No errors email: No errors gender: 0: No errors 1: No errors submit: No errors name: No errors surname: No errors email: No errors gender: 0: No errors 1: No errors submit: No errors

But I don't understand how can i Catch that error. I'm using Symfony 2.3

4

1 Answer 1

2

Forms can handle only POST and GET requests. You can see here why PUT and DELETE have not been added as form methods.

You can send PUT requests only through AJAX calls.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, but If i use php app/console generate:doctrine:crud Symfony creates all methods to manage users (for example) In its methods there are even PUT, and it's works. My Code is the same, but doesn't work
Symfony2 will mimic PUT behavior, adding an hidden _method field. OP question is valid

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.