title: Symfony FormBuilder CollectionType with two fields
body: <p>Target: The User can add more than one entities with one form. Every entity have two fields. In this Case: Barcode and Value.</p>
  
  <p>Problem: I get an empty array when I submit the form.</p>
  
  <p><strong>The Formbuilder for a single entity</strong></p>
  
  <p>NewBarcodeForm</p>
  
  <pre><code>class NewBarcodeForm extends AbstractType
  {
      public function buildForm(FormBuilderInterface $builder, array $options)
      {
          $builder
              -&gt;add('barcode')
              -&gt;add('value')
          ;
      }
  
      public function configureOptions(OptionsResolver $resolver)
      {
          $resolver-&gt;setDefaults([
              'data_class' =&gt; 'AppBundle\Entity\Barcode'
          ]);
      }
  
      public function getBlockPrefix()
      {
          return 'app_bundle_new_barcode_form';
      }
  }
  </code></pre>
  
  <p><strong>The Formbuilder for a list of barcodes</strong></p>
  
  <p>NewBarcodesForm</p>
  
  <pre><code>class NewBarcodesForm extends AbstractType
  {
      public function buildForm(FormBuilderInterface $builder, array $options)
      {
          $builder
              -&gt;add('barcodes', CollectionType::class, array(
                      'entry_type' =&gt; NewBarcodeForm::class,
                      'allow_add' =&gt; true,
                  )
              );
      }
  
      public function configureOptions(OptionsResolver $resolver)
      {
  
      }
  
      public function getBlockPrefix()
      {
          return 'app_bundle_new_barcodes_form';
      }
  }
  </code></pre>
  
  <p><strong>The Controller</strong></p>
  
  <pre><code>    $form = $this-&gt;createForm(NewBarcodesForm::class);
      $form-&gt;handleRequest($request);
  
      if($form-&gt;isSubmitted() &amp;&amp; $form-&gt;isValid()){
          $barcodes = $form-&gt;getData();
          dump($barcodes);
      return $this-&gt;render('items/newBarcode.html.twig', [
          'barcodesForm' =&gt; $form-&gt;createView()
      ]);
  </code></pre>
  
  <p><strong>The HTML Form</strong></p>
  
  <pre><code>&lt;form name="app_bundle_new_barcodes_form" method="post"&gt;
      &lt;input type="hidden" id="app_bundle_new_barcodes_form__token" name="app_bundle_new_barcodes_form[_token]" value="SFl1xlewaLE1JgGVX5oDc_T1PRSc0-aIUgPSaRLfLSU"&gt;
      &lt;div&gt;
          &lt;table class="table table-condensed table-hover"&gt;
              &lt;thead&gt;
                  &lt;tr&gt;
                      &lt;th&gt; Barcode &lt;/th&gt;
                      &lt;th&gt; Value &lt;/th&gt;
                  &lt;/tr&gt;
              &lt;/thead&gt;
              &lt;tbody id="barcodeTable"&gt;
              &lt;tr&gt;
                  &lt;td class="col-md-10"&gt;
                      &lt;input type="text" id="barcodesForm_barcodes_0_barcode" name="barcodesForm[barcodes][0][barcode]" required="required" class="form-control" value="1111"&gt;
                  &lt;/td&gt;
                  &lt;td class="col-md-2"&gt;
                      &lt;input type="number" id="barcodesForm_barcodes_0_value" name="barcodesForm[barcodes][0][value]" required="required" class="form-control" value="1"&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td class="col-md-10"&gt;
                      &lt;input type="text" id="barcodesForm_barcodes_1_barcode" name="barcodesForm[barcodes][1][barcode]" required="required" class="form-control" value="2222"&gt;
                  &lt;/td&gt;
                  &lt;td class="col-md-2"&gt;
                      &lt;input type="number" id="barcodesForm_barcodes_1_value" name="barcodesForm[barcodes][1][value]" required="required" class="form-control" value="22"&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td class="col-md-10"&gt;
                      &lt;input type="text" id="barcodesForm_barcodes_2_barcode" name="barcodesForm[barcodes][2][barcode]" required="required" class="form-control" value="3333"&gt;
                  &lt;/td&gt;
                  &lt;td class="col-md-2"&gt;
                      &lt;input type="number" id="barcodesForm_barcodes_2_value" name="barcodesForm[barcodes][2][value]" required="required" class="form-control" value="333"&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
  
          &lt;/table&gt;
      &lt;/div&gt;
      &lt;button type="submit"&gt;Speichern&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p><strong>Result from dump</strong></p>
  
  <blockquote>
    <p>array:1 [▼   "barcodes" => [] ]</p>
  </blockquote>
  
  <p><strong>EDIT</strong></p>
  
  <p>The HTML above is a simplified result of the twig file, after adding 3 barcodes. The original twig file looks like this:</p>
  
  <pre><code>{% block body %}
      &lt;div id="popDiv" class="ontop"&gt;
          &lt;div class="panel panel-info" id="popup"&gt;
              &lt;div class="panel-heading"&gt;
                  &lt;h3 class="panel-title"&gt;Barcode-Erfassung gestartet.&lt;/h3&gt;
              &lt;/div&gt;
              &lt;div class="panel-body"&gt;
                  {{ form_start(barcodesForm) }}
                  {{ form_row(barcodesForm._token) }}
                  &lt;div&gt;
                      &lt;table class="table table-condensed table-hover"&gt;
                          &lt;thead&gt;
                          &lt;tr&gt;
                              &lt;th&gt; Barcode &lt;/th&gt;
                              &lt;th&gt; Anzahl &lt;/th&gt;
                          &lt;/tr&gt;
                          &lt;/thead&gt;
                          &lt;tbody id="barcodeTable"&gt;
                          &lt;/tbody&gt;
                      &lt;/table&gt;
                  &lt;/div&gt;
                  &lt;div class="alert alert-danger" id="barcodeError" style="display: none"&gt;
                      &lt;strong&gt;Fehler!&lt;/strong&gt; Der Barcode ist bereits in der Liste.
                  &lt;/div&gt;
                  &lt;button type="submit" class="btn default blue-stripe pull-right" onClick="hide('popDiv')"&gt;Speichern&lt;/button&gt;
                  &lt;button class="btn default pull-right" style="margin-right: 10px" onClick="hide('popDiv')"&gt;Abbrechen&lt;/button&gt;
                  {{ form_end(barcodesForm, {'render_rest': false}) }}
                  &lt;!-- TODO: Abbrechen --&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;button class="btn default" onClick="pop('popDiv')"&gt;Click here to open a popup div&lt;/button&gt;
  
  {% endblock %}
  
  {% block javascripts %}
      {{ parent() }}
      &lt;script type="text/javascript" src="{{ asset('plugins/jquery.scannerdetection.js') }}"&gt;&lt;/script&gt;
      &lt;script type="text/javascript"&gt;
          var barcodes = [];
          i = 0;
          function scan() {
              $(document).scannerDetection({
                  timeBeforeScanTest: 200, // wait for the next character for upto 200ms
                  startChar: [120], // Prefix character for the cabled scanner (OPL6845R)
                  endChar: [13], // be sure the scan is complete if key 13 (enter) is detected
                  avgTimeByChar: 40, // it's not a barcode if a character takes longer than 40ms
                  onComplete: function(barcode, qty){
                      if(barcodes.indexOf(barcode) === -1){
                          document.getElementById('barcodeError').style.display = 'none';
                          barcodes.push(barcode);
                          var tr = document.createElement('tr');
                          tr.innerHTML = '' +
                              '&lt;td class="col-md-10"&gt;&lt;input type="text" id="barcodesForm_barcodes_'+i+'_barcode" name="barcodesForm[barcodes]['+i+'][barcode]" required="required" class="form-control" value="'+ barcode +'"&gt;&lt;/td&gt;' +
                              '&lt;td class="col-md-2"&gt;&lt;input type="number" id="barcodesForm_barcodes_'+i+'_value" name="barcodesForm[barcodes]['+i+'][value]" required="required" class="form-control" value="1"&gt;&lt;/td&gt;'
                          ;
                          i++;
                          document.getElementById('barcodeTable').appendChild(tr);
                      }else{
                          document.getElementById('barcodeError').style.display = 'block';
                      }
                  }
              });
          }
  
          function pop(div) {
              document.getElementById(div).style.display = 'block';
              scan();
          }
  
          function hide(div) {
              document.getElementById(div).style.display = 'none';
              $(document).scannerDetection(false);
          }
      &lt;/script&gt;
  {% endblock %}
  </code></pre>