title: how to retrieve data from a form in the controller of an api rest in symfony
body: <p>I am registering a doctor in my api through my symfony controller. And for that I created a form for the doctor, and then I have to persist these data in my database. And that's where I can not get the data from the form, that's what I tried on my postman, but it returns me a 500 error saying: </p>
  
  <blockquote>
    <p>Child \"username\" does not exist.</p>
  </blockquote>
  
  <p>I'm trying to recover my form data through this query:</p>
  
  <blockquote>
    <p>$user->setUsername($form['username']);</p>
  </blockquote>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>  /**
   * @Route("/api/inscription/medecin")
   * @Rest\View(statusCode=Response::HTTP_CREATED)
   * @Method("POST")
   */
     public function postDocAction(Request $request){
  
       $medecin = new Medecin();
      $user = new User();
      $user-&gt;setSalt('');
      $form = $this-&gt;createForm('Doctix\MedecinBundle\Form\MedecinType', $medecin);
  
      $form-&gt;submit($request-&gt;request-&gt;all()); // Validation des données
  
      if ($form-&gt;isValid()){
       $encoder = $this-&gt;get('security.password_encoder');
       $encoded = $encoder-&gt;encodePassword($user, $user-&gt;getPlainPassword());
          $user-&gt;setPassword($encoded);
          $user-&gt;setUsername($form['username']);
          $user-&gt;setRoles(array('ROLE_MEDECIN'));
  
          $user-&gt;setNom($form['nom']);
          $user-&gt;setPrenom($form['prenom']);
          $user-&gt;setNumTel($form['numTel']);
          $user-&gt;setAdresse($form['adresse']);
  
          $medecin-&gt;setUser($user);
          $medecin-&gt;setSexe($form['sexe']);
          $medecin-&gt;setQuartier($form['quartier']);
          $medecin-&gt;setNumOrdre($form['numordre']);
          $medecin-&gt;setSpecialite($form['specialite']);
          $medecin-&gt;setClinique($form['clinique']);
  
          $em = $this-&gt;getDoctrine()-&gt;getManager();
          $em-&gt;persist($medecin);
          $em-&gt;flush();
    }
     }
  </code></pre>
  
  <p><strong>Form</strong></p>
  
  <pre><code>   class MedecinType extends AbstractType
  {
  /**
   * @param FormBuilderInterface $builder
   * @param array $options
   */
  public function buildForm(FormBuilderInterface $builder, array $options)
  {
      $builder
          -&gt;add('user',UserType::class)
          -&gt;add('sexe',  TextType::class)
          -&gt;add('specialite',SpecialiteType::class)
          -&gt;add('clinique',CliniqueType::class)
          -&gt;add('quartier',  TextType::class)
          -&gt;add('numordre',  TextType::class)
      ;
  }
  
  /**
   * @param OptionsResolver $resolver
   */
  public function configureOptions(OptionsResolver $resolver)
  {
      $resolver-&gt;setDefaults(array(
          'data_class' =&gt; 'Doctix\MedecinBundle\Entity\Medecin',
          'csrf_protection' =&gt; false
      ));
  }
  }
  </code></pre>
  
  <p><strong>Test in Postman</strong></p>
  
  <p><a href="https://i.stack.imgur.com/wpr2w.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wpr2w.png" alt="registertest"></a></p>