title: Symfony2 custom form type key pair
body: <p>I'm currently trying to implement a key-pair value for a form type, which is used together with the FOSRestBundle to allow for sending a request like the following:</p>
  <pre><code>{
      &quot;user&quot;: {
          &quot;username&quot;: &quot;some_user&quot;,
          &quot;custom_fields&quot;: {
              &quot;telephone&quot;: &quot;07777&quot;,
              &quot;other_custom_field&quot;: &quot;other custom value&quot;
          }
      }
  }
  </code></pre>
  <p>The backend for this is represented as follows:</p>
  <blockquote>
  <p><em>User</em></p>
  <p>id, username, customFields</p>
  <p><em>CustomUserField</em></p>
  <p>id, field</p>
  <p><em>CustomUserFieldValue</em></p>
  <p>user_id, field_id, value</p>
  </blockquote>
  <p>I've currently made a custom form as follows:</p>
  <pre><code>&lt;?php
  
  class UserType extends AbstractType
  {
      public function buildForm(FormBuilderInterface $builder, array $options)
      {
          $builder
              -&gt;add('username')
              -&gt;add(
                  'custom_fields',
                  'user_custom_fields_type'
              )
          ;
      }
  
      public function setDefaultOptions(OptionsResolverInterface $resolver)
      {
          $resolver-&gt;setDefaults(
              array(
                  'data_class'      =&gt; 'Acme\DemoBundle\Entity\User',
                  'csrf_protection' =&gt; false,
              )
          );
      }
  
      public function getName()
      {
          return 'user';
      }
  }
  </code></pre>
  <p>And my <code>user_custom_fields_type</code>:</p>
  <pre><code>&lt;?php
  
  class CustomUserFieldType extends AbstractType
  {
      private $em;
  
      /**
       * @param EntityManager $em
       */
      public function __construct(EntityManager $em)
      {
          $this-&gt;em = $em;
      }
  
      public function buildForm(FormBuilderInterface $builder, array $options)
      {
          $fields = $this-&gt;em-&gt;getRepository('AcmeDemoBundle:CustomUserField')-&gt;findAll();
  
          foreach($fields as $field) {
              $builder-&gt;add($field-&gt;getField(), 'textarea');
          }
      }
  
      public function setDefaultOptions(OptionsResolverInterface $resolver)
      {
          $resolver-&gt;setDefaults(
              array(
                  'invalid_message' =&gt; 'The selected custom field does not exist'
              )
          );
      }
  
      public function getParent()
      {
          return 'collection';
      }
  
      public function getName()
      {
          return 'user_custom_fields_type';
      }
  }
  </code></pre>
  <p>This keeps giving me the error that there are extra fields. Which are the ones I've added in the <code>CustomUserFieldType</code>. How can I get this working?</p>
  <p>Note: this is a simplified version of the actual code, I've tried removing all the irrelevant code.</p>