Access embedded form data symfony
<p>i am working with embedded forms within symfony and cannot get the data from the embedded form. </p>

<p>This is my Patent Form </p>

<pre><code>namespace AppBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use AppBundle\Form\SubscriberAddressType;

class SubscriberDetailsType extends AbstractType {
    /**
     * @param FormBuilderInterface $builder
     * @param array                $options
     */
    public function buildForm(FormBuilderInterface $builder, array $options) {

        $builder
            -&gt;add('firstname', TextType::class, [
                'label' =&gt; false,
                'required' =&gt; true,
                'error_bubbling' =&gt; true,
                'attr' =&gt; [
                    'placeholder' =&gt; 'First Name',
                    'class' =&gt; 'form-control'
                    ]])
            -&gt;add('lastname', TextType::class, [
                'label' =&gt; false,
                'required' =&gt; true,
                'error_bubbling' =&gt; true,
                'attr' =&gt; array(
                    'placeholder' =&gt; 'Last Name',
                    'class' =&gt; 'form-control'
                )])
            -&gt;add('emailaddress', EmailType::class, [
                'label' =&gt; false,
                'required' =&gt; true,
                'error_bubbling' =&gt; true,
                'attr' =&gt; [
                    'placeholder' =&gt; 'Email Address',
                    'pattern'     =&gt; '.{2,}',//minlength
                    'class' =&gt; 'form-control'
                    ]])
            -&gt;add('subscriberaddress', CollectionType::class, ['entry_type' =&gt; SubscriberAddressType::class])
            -&gt;add('submit', SubmitType::class, [
                'label' =&gt; 'Sign Up',
                'attr' =&gt; [
                    'class' =&gt; 'smoothScroll btn btn-danger sb-button'
                    ]
        ])
             ;
    }

    /**
    * @param OptionsResolverInterface $resolver
    */
    public function configureOptions(OptionsResolver $resolver) {
        $resolver-&gt;setDefaults(['data_class' =&gt; 'AppBundle\Entity\SubscriberDetails']);
    }
    /**
     * @return string
     */
    public function getName() {
        return 'subscriberdetails';
    }
}
</code></pre>

<p>This is my child form</p>

<pre><code>namespace AppBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\TextType;

class SubscriberAddressType extends AbstractType {
    /**
     * @param FormBuilderInterface $builder
     * @param array                $options
     */
    public function buildForm(FormBuilderInterface $builder, array $options) {

        $builder
            -&gt;add('address1', TextType::class, [
                'label' =&gt; false,
                'required' =&gt; true,
                'error_bubbling' =&gt; true,
                'attr' =&gt; [
                    'placeholder' =&gt; 'Address 1',
                    'class' =&gt; 'form-control'
                    ]])
            -&gt;add('city', TextType::class, [
                'label' =&gt; false,
                'required' =&gt; true,
                'error_bubbling' =&gt; true,
                'attr' =&gt; array(
                    'placeholder' =&gt; 'City',
                    'class' =&gt; 'form-control'
                )])
             ;
    }

    /**
    * @param OptionsResolverInterface $resolver
    */
    public function configureOptions(OptionsResolver $resolver) {
        $resolver-&gt;setDefaults(['data_class' =&gt; 'AppBundle\Entity\SubscriberAddress']);
    }
    /**
     * @return string
     */
    public function getName() {
        return 'subscriber';
    }
}
</code></pre>

<p>This is how i call the embedded form in my twig template</p>

<pre><code>        &lt;div class="form-group "&gt;        
            {% for field in form.subscriberaddress %}
                {{ form_label(field.city) }}
                {{ form_widget(field.city) }}
            {% endfor %}           
        &lt;/div&gt;
</code></pre>

<p>When i am trying to get the data from the form using below:</p>

<pre><code>            $firstname = $form['firstname'] -&gt;getData();
            $lastname =$form['lastname'] -&gt;getData();
            $email = $form['emailaddress'] -&gt;getData();
            $address = $form['subscriber address']['address1'] -&gt;getData();
            $city =$form['subscriber address']['city'] -&gt;getData();
</code></pre>

<p>it works fine for above first 3 lines but when it gets to  $address = $form['subscriber address']['address1'] ->getData(); with is an embedded field, symfony shoots an error child element does not exist.</p>

<p>I have tried going though official symfony cookbook as well as these posts 
<a href="https://stackoverflow.com/questions/29485240/how-to-get-data-from-a-form-in-symfony2">Post1</a>, <a href="https://stackoverflow.com/questions/8987418/how-to-get-form-values-in-symfony2-controller">Post2</a> but none of these seem to answer my question, which is: how do i get the data from embedded fields in the form?</p>