Susan
Susan

Reputation: 97

Symfony Twig: send a set parameter with a form submit request

I have a form in my twig, i want that by clicking on its submit button, another parameter (that i've set in the twig) get sent to the same action that handles the form : this is the variable i've set

 {% set idprof = profil.id %}

I want to send it with the submit request : ( i know this code is false)

{{ form_widget(form.id),{'idprof': idprof} }}

and the action will look like this :

public function gestProfAction(Request $request, $idprof)
    {
}

I'm sorry i know this is a stupid question, but I'm still new in symfony, I couldn't find a solution by myself.

Upvotes: 0

Views: 4815

Answers (1)

Renan Taranto
Renan Taranto

Reputation: 572

Just pass it in the form start line

{{ form_start(form, {'action': path('idprof', { 'idprof': idprof })}) }}

Remember to add the annotation or yaml for the routing

/**
* @Route("/idprof/{idprof}", name="idprof")
*/
public function gestProfAction(Request $request, $idprof)
{
}

For reference:

Upvotes: 1

Related Questions