Dipeca
Dipeca

Reputation: 51

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

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

Upvotes: 5

Views: 630

Answers (1)

Vince V.
Vince V.

Reputation: 3143

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.

Upvotes: 2

Related Questions