我无法从我的其中一个表格中获取数据
i can't get data from one of my forms
我创建了一个包含两个表单的页面我想在提交按钮时获取每个表单的数据,这里的问题是我只能获取其中一个表单的数据
这是我的 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()));
}
当我尝试插入 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
您只为其中一个表单调用了 handleRequest。两者都需要调用它。
添加$formDemanceCCP->handleRequest($this->get('request'));
我创建了一个包含两个表单的页面我想在提交按钮时获取每个表单的数据,这里的问题是我只能获取其中一个表单的数据
这是我的 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()));
}
当我尝试插入 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
您只为其中一个表单调用了 handleRequest。两者都需要调用它。
添加$formDemanceCCP->handleRequest($this->get('request'));