How to relate two input field in a symfony 3 form
<p>Please how can I achieve this.i have two choice fields(entity) such as category and skills. I want the  skills field to be dependent on category i.e if a category is selected the options of the skill should be the skills related to that category  but if no category is selected, the options of the field should be all the skills. </p>

<blockquote>
  <p>NOTE THE CODE BELOW IS JUST FOR ILLUSTRATION PURPOSE</p>
</blockquote>

<pre><code>   public function buildForm(FormBuilderInterface $builder, array $options)
{


    $builder
        if ( a value is selected from
             (-&gt;add('category', EntityType::class, array(
            'class'=&gt;'AppBundle:Category',
            'choice_label'=&gt;'name'
             ))) )
        {
                present skills based on the selected category as

                ( -&gt;add('skill', EntityType::class, array(
                    'class'=&gt;'AppBundle:Skill',
                    'choice_label'=&gt;'name',

                    'query_builder' =&gt; function (EntityRepository $er) {
                        return $er-&gt;createQueryBuilder('s')
                            -&gt;select('s')
                            -&gt;where('c = :category')
                            -&gt;setParameter('category', $value selected from category);
                    },

                )))
}else{

 -&gt;add('skill', EntityType::class, array(
    'class'=&gt;'AppBundle:skill',
    'choice_label'=&gt;'name'
    ))
</code></pre>

<p>}</p>