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 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改