title: How to get data from select field Symfony
body: <p>Hi everyone i have problem. I need to take data from Select field filled by entity class.</p>
  
  <p>This is my entity: It's dictionary with months and first and last day. </p>
  
  <p><strong>Entity</strong></p>
  
  <pre><code>namespace accountant\ReportBundle\Entity;
  
  use Doctrine\ORM\Mapping as ORM;
  
  /**
   * @ORM\Entity
   */
  class Calendar
  {
      /**
       * @var integer
       *
       * @ORM\Column(name="id", type="integer")
       * @ORM\Id
       * @ORM\GeneratedValue(strategy="AUTO")
       */
      private $id;
  
      /**
       * @var string
       *
       * @ORM\Column(name="month", type="string", length=255)
       */
      private $month;
  }
  </code></pre>
  
  <p>I load fixtures to this table to db and create formBuilder: </p>
  
  <p><strong>FormType</strong></p>
  
  <pre><code>class ReportFormType extends AbstractType
  {
       public function buildForm(FormBuilderInterface $builder, array $options)
      {
          $builder
              -&gt;add('month','entity', array(
                  'class' =&gt; 'ReportBundle:Calendar',
                  'property' =&gt; 'month',
                  'expanded' =&gt; false,
                  'multiple' =&gt; false
              ));
      }
  }
  </code></pre>
  
  <p>Now I want to get data from selected month to, but <code>$data</code> is <code>null</code>: </p>
  
  <p><strong>Controller</strong></p>
  
  <pre><code> /**
   * @Route("/report", name="report")
   * @Template()
   */
  public function indexAction(Request $request)
  {
      $form = $this-&gt;createForm(new ReportFormType());
      $form-&gt;handleRequest($request);
      $data = $form-&gt;getData();
  
      var_dump($data);    // $data is null!       
  
      return array('form' =&gt; $form-&gt;createView());
  }
  </code></pre>
  
  <p><strong>TWIG</strong></p>
  
  <pre><code>&lt;form method="get" action="{{ path('report') }}"&gt;
      &lt;div class="form-group"&gt;
          {{ form_row(form.month, {'label': 'Select Month:', 'attr': {'class': 'form-control'}}) }}
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
          &lt;input type="submit" value="Show Report" class="btn btn-warning btn-block"/&gt;
      &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p><strong>UPDATE 1</strong></p>
  
  <p>I add 'data_class' but i still get NULL. </p>
  
  <pre><code> public function buildForm(FormBuilderInterface $builder, array $options)
  {
      $builder
          -&gt;add('month','entity', array(
              'class' =&gt; 'ReportBundle:Calendar',
              'choice_label' =&gt; 'month',
              'expanded' =&gt; false,
              'multiple' =&gt; false,
          ));
  }
  
  /**
   * @param OptionsResolver $resolver
   */
  public function configureOptions(OptionsResolver $resolver)
  {
     $resolver-&gt;setDefaults(array(
         'data_class' =&gt; Calendar::class
     ));
  }
  </code></pre>
  
  <p>This is my Controller now. </p>
  
  <pre><code>public function indexAction(Request $request)
  {
      $form = $this-&gt;createForm(new ReportFormType());
      $form-&gt;handleRequest($request);
      $data = $form-&gt;get('month')-&gt;getData();
      // i check data
      var_dump($data);
  
      return array(
          'form' =&gt; $form-&gt;createView());
  }
  </code></pre>
  
  <p><strong>UPDATE 2</strong></p>
  
  <p>I solved my problem i change my form in template for this:</p>
  
  <pre><code>&lt;form method="post" action="{{ path('report') }}" novalidate="novalidate"&gt;
  {{ form_errors(form) }}
  &lt;div class="form-group"&gt;
  {{ form_row(form.month, {'label': 'Select month', 'attr': {'class': 'form-control'}}) }}
  {{ form_rest(form) }}
  &lt;/div&gt;
  &lt;div class="form-group"&gt;
      &lt;input type="submit" value="Show report" class="btn btn-warning btn-block"/&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p></p>
  
  <p>I change method to <code>post</code> and add <code>form_rest</code></p>