【问题标题】:i can't get data from one of my forms我无法从我的一种表格中获取数据
【发布时间】:2016-09-06 04:52:12
【问题描述】:

我创建了一个包含两个表单的页面,我想在提交按钮时获取每​​个表单的数据,这里的问题是我只能为其中一个表单获取数据

这是我的 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, 职业, nationalite, typePieceIdentite, numeroIdentite, adresse, email, tel, codePostal, sollicite, dateDemancde, statut) 值 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)' 带参数 [null, null, null, null, null, null, null, 空,空,空,空,空,空,“2016-05-11 03:25:36”,“在路上”]:

SQLSTATE[23000]:违反完整性约束:1048 列 'nom' 不能为空

【问题讨论】:

    标签: symfony symfony-2.6


    【解决方案1】:

    您只为您的一种表单调用了handleRequest。两者都需要调用它。

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

    【讨论】:

      猜你喜欢
      • 2017-05-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-15
      • 1970-01-01
      • 2018-06-09
      相关资源
      最近更新 更多