title: How to use multiple form types in symfony to create a single form with data class
body: <p>Firstly, let me admit that I am an amateur in symfony forms. Any help would be really appreciated. I am not allowed to share the actual code and hence I am using some example code to demonstrate the use case.</p>
  
  <p>Given below is the use case,</p>
  
  <p>I have an entity called testEntity,</p>
  
  <pre><code>class testEntity {
      private $property1;
      private $property2;
      private $property3;
  
      //with setters and getters
  }
  </code></pre>
  
  <p>I have a form type called formType1,</p>
  
  <pre><code>    class formType1 extends AbstractType {
          public function buildForm(FormBuilderInterface $builder, array $options) {
              $builder
                  -&gt;add('property2')
                  -&gt;add('property3)
              ;
          }
  
          public function buildView() {
             // Code that create view vars
          }
      }
  </code></pre>
  
  <p>And I have a form type for testEntity,</p>
  
  <pre><code>class testEntityType extends AbstractType {
      public function buildForm(FormBuilderInterface $builder, array $options) {
          $builder-&gt;add('property1)
          ....
      }
  
      public function configureOptions(OptionsResolver $resolver) {
          $resolver-&gt;setDefaults([
              'data_class' =&gt; testEntity::class
          ]);
      }
  }
  </code></pre>
  
  <p>formType1 is a form type with out data class and with it's own template and will be used by itself. What I want to do is to re-use formType1 in testEntityType as formType1 has the fields that map to testEntity's properties so that when submitted I could get testEntity object with the form data and I can also get formType1's view in my final form.</p>
  
  <p>Controller action has this,</p>
  
  <pre><code>$testEntity = new testEntity();
  $form = $this-&gt;createForm(PostType::class, $testEntity);
  </code></pre>
  
  <p>so that when, the form submits I get $testEntity with the data from form</p>
  
  <p>Apologies in advance, if I haven't framed the question well enough to be understood.</p>
  
  <p><strong>Got this working by doing this,</strong></p>
  
  <pre><code>class testEntityType extends AbstractType {
      public function buildForm(FormBuilderInterface $builder, array $options) {
          $builder-&gt;add('property1')
              -&gt;add('formType1', formType1::class, [
                   'mapped' =&gt; false,
                   'data' =&gt; $options['data']
              ])
          ....
      }
  
      public function configureOptions(OptionsResolver $resolver) {
          $resolver-&gt;setDefaults([
              'data_class' =&gt; testEntity::class
          ]);
      }
  }
  </code></pre>
  
  <p>Passed data via options and sett <code>mapped</code> to <code>false</code>. </p>