title: Pass data from entity form to controller Symfony3
body: <p>I have entity type class field (dropdown) which generate data from one of my table. I have form sub-agent where user will select a company for that particular sub-agent. </p>
  
  <pre><code>public function buildForm(FormBuilderInterface $builder, array $options)
  {
  
      $builder-&gt;add('company_id', EntityType::class, array(
          'label' =&gt; 'Company',
          'required' =&gt; true,
          'class' =&gt; 'OnlyBundle\Entity\Company',
          'choice_label' =&gt; 'name', // The Company Name
          'choice_value' =&gt; 'id', // The Company ID (unique) to be inserted in DB
          'expanded' =&gt; false,
          'multiple' =&gt; false,
          'placeholder' =&gt; 'Choose a Company',
          'constraints' =&gt; array(
              new NotBlank(array("message" =&gt; 'Company name is required.')),
          ),            
      ));  
  </code></pre>
  
  <p>This entity will generate twig like below.</p>
  
  <pre><code>    &lt;select id="sub_agent_company_id" name="sub_agent[company_id]" required="required"&gt;
      &lt;option value="" selected="selected"&gt;Choose a Company&lt;/option&gt;
      &lt;option value="20"&gt;ABC&lt;/option&gt;
      &lt;option value="21"&gt;EFG&lt;/option&gt;
  &lt;option value="22"&gt;HIJ&lt;/option&gt;
      &lt;/select&gt;
  </code></pre>
  
  <p>I want to pass or set the value of dropdown field (20, 21, 22) into my controller, but the problem is, the drop down returns an object from my company class. How do I pass only the value of dropdown and not the whole controller?</p>
  
  <p>Here's my controller.</p>
  
  <pre><code>   public function createAction(Request $request) {
  
          $sub_agent = new Sub_agent;
  
          $form = $this-&gt;createForm(SubAgentType::class, $sub_agent, array(
              'action'=&gt;$this-&gt;generateUrl('swipe_backend_sub_agent_create'),
              'method'=&gt;'POST'
          ));
  
          $form-&gt;handleRequest($request);
  
           if ('POST' === $request-&gt;getMethod()) {
  
              $data = $form-&gt;getData();
  
              $sub_agent_name = $data-&gt;getName();
  
              var_dump($data-&gt;getCompanyId()); exit;
  
  ..../
  </code></pre>