我创建了一个带有两个表单的页面,我想在提交按钮时获取每个表单的数据,这里的问题是我只能获取其中一个表单的数据
这是我的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的数据时,我得到了这个异常
执行“INSERT INTO DemandeCCP(nom,
prenom、dateNaissance、lieuNaissance,专业,国有化,
typePieceIdentite、numeroIdentite,地址,电子邮件,电话,代码邮政,
sollicite,dateDemancde,statut)值(?,
?, ?, ?, ?, ?)' 带有参数[null,null,null,null,null,
null,null,null,nullnull,空,空,“2016-05-11 03:25:36”,“en cour”]:
SQLSTATE[23000]:完整性约束冲突:1048列“nom”
不能为空