The Symfony documentation explains how to add a field based on the value of an other field for a submitted form: http://symfony.com/doc/2.3/cookbook/form/dynamic_form_modification.html#cookbook-form-events-submitted-data
However, how to add a field based on the value of 2 other fields?
Let's say I have these 3 fields in my form:
Each of these fields are entity
fields, but only brands of the selected category should be shown (easily done with the mentioned cookbook, using the FormEvents::POST_SUBMIT
event), and only models of the selected category and brand (if they are both submitted) should be shown in the list.
This means that I need to get the submitted values of both the brand and the model to get the list of available models.
How can I achieve that?
You need to use form event subscribers. More on that:
Add event listener to form element added by event listener
http://showmethecode.es/php/symfony/symfony2-4-dependent-forms/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.