Symfony - Use underscore or dot instead of brackets with FormType in URL query (get method)

43 Views Asked by At

I search to use underscore or dot instead of brackets with FormType in URL query with GET method.

Current

I've actually this URL when I submit my form:

/path?fieldName%5BsubFieldName%5D=toto

Or this (decoded):

/path?fieldName[subFieldName]=toto

Expected

I'd like to have this:

/path?fieldName_subFieldName=toto

Or this:

/path?fieldName.subFieldName=toto

Tried

I tried a few options in the form configuration but I don't know what they correspond to, and I don't know where to google (what terms to use).

1

There are 1 best solutions below

0
On

It's the normal behaviour of Symfony Form Component. To avoid this, you should use named form builder, like this :

public function controllerMethod(FormFactory $formFactory) {
    $form = $formFactory->createNamed(
        '',                 // Your form name
        MyFormType::class, // Your form type
        [],               // data
        []               // form options
    );

    // Do something
}

For the button, you have to remove it from your Form class (i mean, the SubmitType one), and add it manually tou your html (with classical <button></button> inside of your form rendering)