Symfony - How to pass a variable to an embedded form

Course Queries Syllabus Queries 3 years ago

2.09K 2 0 0 0

User submissions are the sole responsibility of contributors, with TuteeHUB disclaiming liability for accuracy, copyrights, or consequences of use; content is for informational purposes only and not professional advice.

Answers (2)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 3 years ago

I'm facing a problem with Symfony3 and forms.

I have a Parent form with an embedded Child form. From the controller, I can send data I can use in the Parent form with the $options array ($options['varA'], ...).

$form = $this->createForm(ParentEntityType::class, $objParent, array('varA'=>$varA, 'varB'=>$varB));

But what if I want to pass the varB variable (for example) to the embedded form ? What's the proper solution ?

Any help will be appreciated, thanks.

0 views
0 shares

profilepic.png
manpreet 3 years ago

Something like this, in the first form:

$builder->add('name', MyFormType::class, [
            'data' => $options['varB']
]);

But better if you share your forms codes. The main key is to pass variables by $options['key'] in buildForm() method.


0 views   0 shares

No matter what stage you're at in your education or career, TuteeHUB will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.

Similar Forum