2013-06-07 2 views
1

양식 데이터가 데이터베이스에 저장되기 전에 작업을 수행 할 수 있어야합니다. 문제는 조작이 위험 할 수 있으며 매번 사용자의 동의가 필요하다는 것입니다.Symfony2 양식 제출 확인

Javascript 확인 ​​창이 아닌 확인 양식 (진행 상황을 설명하는 작은 메시지 포함)을 통해이 작업을 수행하고 싶습니다.

이 기능을 어떻게 수행 할 수 있습니까? 당신은 여러 단계의 형태를 만들 수있는 CraueFormFlowBundle로 볼 수도 있습니다

<?php 
public function indexAction(Request $request) 
{ 
    ... 

    $form = $this->createFormBuilder($myEntity) 
     ->add('someField', 'integer', array('required' => true)) 
     // Lots and lots of fields 
     ->getForm(); 

    if ($request->isMethod('POST')) { 
     $form->bind($request); 

     if ($form->isValid()) { 
      // CUSTOM VALIDATION HERE 

      // If invalid, must display a new confirmation form to ask user 
      // if it's alright to do a somewhat risky operation that would 
      // validate the form data. 

      // Else, persist the data. 
      $db = $this->getDoctrine()->getManager(); 
      $db->persist($myEntity); 
      $db->flush(); 

      return $this->redirect($this->generateUrl('my_path_to_success_page')); 
     } 
    } 

    return $this->render('MyBundle:Preferences:index.html.twig', array(
     'form' => $form->createView(), 
     'errors' => $form->getErrors(), 
    )); 
} 

답변

0

: 여기

양식을 처리하는 컨트롤러 액션 메소드의 예입니다.