symfonysymfony-2.6

i can't get data from one of my forms


I create a page with two form i want to get data of each form when the button is submitted, the probleme here is i can get data just for one of the form

this is my indexAction :

    public function indexCcpAction ()
{

    $demanceCCP = new DemandeCCP();
    $ccp = new Ccp();
    $formDemanceCCP = $this->createForm(new DemandeCcpType(), $demanceCCP);
    $formCcp = $this->createForm(new LoginCcpType(), $ccp);
    $formCcp->handleRequest($this->get('request'));
    $em = $this->getDoctrine()->getManager();
    if ( $this->get("request")->getMethod() == "POST" ) {
            if ($this->get("request")->request->has("DemandeCcpType")  ) {
                $demanceCCP = $formDemanceCCP->getData(); // i can't get data from this form
                echo($demanceCCP->getNom());
                $em->persist($demanceCCP);
                $em->flush();
            }
            if ($this->get("request")->request->has("LoginCcpType")) {
                $ccp = $formCcp->getData(); // but in this form work
                echo ($ccp->getMdp());
            }
    }
    return $this->render('EgovPosteBundle:Ccp:DemanceCCP.html.twig',
        array('formDemandeCcp'=>$formDemanceCCP->createView(),
              'formLogin'=>$formCcp->createView()));
}

I get this exception when i try to insert data of the DemandeCcpType

An exception occurred while executing 'INSERT INTO DemandeCCP (nom, prenom, dateNaissance, lieuNaissance, profession, nationalite, typePieceIdentite, numeroIdentite, adresse, email, tel, codePostal, sollicite, dateDemancde, statut) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)' with params [null, null, null, null, null, null, null, null, null, null, null, null, null, "2016-05-11 03:25:36", "en cour"]:

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'nom' cannot be null


Solution

  • You have only called handleRequest for one of your forms. It needs to be called for both.

    Add $formDemanceCCP->handleRequest($this->get('request'));