I'm using a form(parent form) with a collection field type(child forms). Each type in the collection is a form that contains some choice fields, I want to filter this field choices using query_builder parameter for join with other entities ect. I know how to pass parameters to parent form from controller, but how to pass parameters to each item in the collection (child forms)?
Asked
Active
Viewed 2,923 times
3 Answers
1
What you want is a data transformer. The data transformer takes data from your sub forms allows you to do queries to the database from inside it and pass 1 final result out the end. I had to do this the other day with country and postal code to find a valid postal code in a country.
Here's the link to the cookbook info that will show you how to use it.
http://symfony.com/doc/current/cookbook/form/data_transformers.html

thenetimp
- 9,487
- 5
- 29
- 42
0
Here is my answer: https://stackoverflow.com/a/17223519/1756517
In each form, pass the variable by the construct method ($form = new FormType($your_variable);)
0
A bit late response, but with Symfony3, you should use the entry_options
parameter as mentioned here. It was exactly what I needed, in scenario similar to yours.

userfuser
- 1,350
- 1
- 18
- 32