ds78662302 2014-12-03 09:00
浏览 34
已采纳

在symfony2上更改表单(如草稿/完成)

I want to make forms which has three scenes

1.input view (which has 'confirm' button) 2.draft check view (which has 'send' button) 3.send view

in method 1 you can input the data then click 'confirm' button

the system write the data in DB as draft.

in method 2 you see the data and confirm then push 'send' button

the system write the flg 'confirmed'

these are my code.

it works well method 1 but if I push 'send' button in method2. it doesn't go.

if ($form->isValid()) {

My idea is something wrong??

public function writeEvalStudentAction(Request $request,$keyStr){

    ...

    $form = $this->createFormBuilder($evalStudent)
    ->add('commentToStudent')
    ->add('confirm','submit')->getForm();

    $form->handleRequest($request); 

    if ($form->isValid()) {
        if ($form->has('send')){
            if ($form->get('send')->isClicked()){

        //set confirm flg then shows thanks screen.

            $evalStudent->setConfirmed(true);
            $em->persist($evalStudent);
            $em->flush();

            return $this->render('AcmeMemberBundle:Default:confirmedEvalStudent.html.twig');
            }
         }
        if ($form->has('confirm')){
            if ($form->get('confirm')->isClicked()){

        // write in the db as draft.
            $evalStudent->setCommentToStudent($form->get('commentToStudent')->getData());

            $em->persist($evalStudent);
            $em->flush();

            $form = $this->createFormBuilder($evalStudent)->add('send','submit')->getForm();
            return $this->render('AcmeMemberBundle:Default:checkEvalStudent.html.twig',
                array('form' => $form->createView()));
        }
    }
    return $this->render('AcmeMemberBundle:Default:writeEvalStudent.html.twig',
            array('form' => $form->createView()));
}
  • 写回答

1条回答 默认 最新

  • duankuai6586 2014-12-03 09:56
    关注

    Split it up in 4 controller actions with 4 separate routes. Whereas route2 and route3 require the id of your draft object in the routing parameters.

    Make the form1 from step 1 point to step2. In step2 validate the form and if it is ok insert to db and get your id, then show form2 which points to step 3, if not show form1 with form errors.

    Same for step2->step3 and step3->step4.

    In step 4 you convert your draft to a final object and persist it and remove the draft.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路