'How to dynamically modify a form field based on 2 other fields in Symfony?

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:

  • Category
  • Brand
  • Model

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?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source