Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony 2 - create a form with a parent entity filtering the options of the child entity

Tags:

html

symfony

I am new to symfony and PHP. I have a problem that I hope someone can help:

supose we have 3 entities.

Groups, specialities, works; works belong to a speciality, speciality belong to a group.

Supose that I want to have a form to create a "work". I want to filter my specialities according to a select with the list of groups ( much like on a travel site where we get the destinations filtered by the origin).

So my form will only have 2 fields. The speciality and a name for the work. But in my view i must have 3 fields, 1 for groups that will filter the specialities and the fields belonging to the form.

Much like a booking flights site I must see the fields from the begining.

This as to be so simple, but I'm really stuck on it.

Thank you

like image 547
Dipeca Avatar asked Nov 05 '22 15:11

Dipeca


1 Answers

At this moment I can come up with 2 solutions:

1) Use ajax. On the request populate a selectbox with the groups. when you select one of the groups, all the specialities come into a different selectbox of that group.

2) Use uri segments. Let the user first choose group, then go to a next page and let them choose a speciality. After that the user gets a form where he fills in the data.

like image 178
Vince V. Avatar answered Nov 15 '22 00:11

Vince V.