title: Symfony2 confirm form submission
body: <p>I need to be able to do an operation on form data before it gets persisted to the database. The problem is, the operation can be risky and I need the user's consent each time. </p>
  
  <p>I'd like to do this through a confirmation form (with a little message explaining what's going on), not with a Javascript confirm window.</p>
  
  <p>How can I achieve this functionality?</p>
  
  <p>Here is an example of a controller action method that handles the form:</p>
  
  <pre><code>&lt;?php
  public function indexAction(Request $request)
  {
      ...
  
      $form = $this-&gt;createFormBuilder($myEntity)
          -&gt;add('someField', 'integer', array('required' =&gt; true))
          // Lots and lots of fields
          -&gt;getForm();
  
      if ($request-&gt;isMethod('POST')) {
          $form-&gt;bind($request);
  
          if ($form-&gt;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-&gt;getDoctrine()-&gt;getManager();
              $db-&gt;persist($myEntity);
              $db-&gt;flush();
  
              return $this-&gt;redirect($this-&gt;generateUrl('my_path_to_success_page'));
          }
      }
  
      return $this-&gt;render('MyBundle:Preferences:index.html.twig', array(
          'form' =&gt; $form-&gt;createView(),
          'errors' =&gt; $form-&gt;getErrors(),
      ));
  }
  </code></pre>