Skip to content
Advertisement

pass id of foreign key to the form via post

I’ve created a new field (“responsavel”) on my db for this entity (“Multa”), “responsavel” is a foreign key to another table (Usuario) and I want it to be shown on my form as an select with just some objects (that’s why the $desligados I’m passing to the front) for the user to choose and then pass it to the back.

I’ve been able to do it with $.postbut I’m doing other things after the submit is passed to the controller so I’ve included a $(this).unbind('submit').submit(); but now it’s like I’m submitting the form two times, and one of them is not submitting with the “responsavel” value.

This is my form:

JavaScript

this is what I have on my controller:

JavaScript

what I’m doing on the front:

JavaScript

A example of one submit on my db: enter image description here

Advertisement

Answer

As Jakumi recommended I used the EntityType::class to create a custom querybuilder, it returned what i wanted and as I’m using the formType to render all the fields I didn’t needed to do anything on the frontend to pass it to my controller.

enter image description here

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement