7

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)?

2
  • 1
    By "parameters" do you mean the $options array that's passed to buildForm()? Commented May 17, 2012 at 17:43
  • Here is something worth trying out: stackoverflow.com/a/20229988/583786 Commented Jun 18, 2014 at 9:59

3 Answers 3

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

Sign up to request clarification or add additional context in comments.

Comments

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);)

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.