Thanks to visit codestin.com
Credit goes to github.com

Skip to content

submitting Form wiht PATCH method (isSubmitted()) not working #40452

Closed
@etshy

Description

@etshy

Symfony version(s) affected: 5.2.3

Description

on a Form with a PATCH method, with the http_method_override options set to true, the form isn't marked as submitted.
The method property of the Request class is already set to POST and so it doesn't pass the first condition of the handleRequest() method.

How to reproduce

set the http_method_override to true and the forme method to PATCH.

Possible Solution

I didn't really look at it in details yet, but from the (dirty) debug I made, the method property of the Request class is already set to POST and so it doesn't pass the first condition of the handleRequest() method.

Additional context

framework.yml

framework:
  secret: '%env(APP_SECRET)%'
  #default_locale: en
  csrf_protection: ~
  http_method_override: true

MyForm.php

    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->setMethod('PATCH');
        ...

MyController

 public function edit(Request $request)
    {
        $form = $this->createForm(MyForm::class, $class);
        $form->handleRequest($request);

        if ($form->isSubmitted()) { // Always false when using PATCH, works when using POST

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions