title: Symfony3 : multi-steps form and flush after forward
body: <p>I have a form to add a new prescriber in my database. The first step consists in informing the various informations about the prescriber.</p>
  
  <p>Then, I check if there are similar prescribers before adding it (2nd step with a 2nd form) and if there are, I ask the user to confirm.</p>
  
  <p>In short, I have a 1-step form or a 2-steps form, depending on duplicates.</p>
  
  <p>I tried with CraueFormFlowBundle but I don't know how to implement my conditional second step. My tests were inconclusive. So I decided to use forward method in my controller, and I like it !</p>
  
  <p>But, I can't manage to flush my prescriber at the end of the 2nd step (after forwarding), I have this error : <code>Unable to guess how to get a Doctrine instance from the request information for parameter "prescriber".</code></p>
  
  <p><strong>addAction (= step 1)</strong></p>
  
  <pre><code>/**
   * Add a new prescriber
   *
   * @Route("/prescribers/add", name="prescriber_add")
   */
  public function addAction(Request $request) {
      $em = $this-&gt;getDoctrine()-&gt;getManager();
      $rp = $em-&gt;getRepository('AppBundle:Prescriber');
      $p  = new Prescriber();
  
      // build the form
      $form = $this-&gt;createForm(AddPrescriberType::class, $p);
  
      // handle the submit
      $form-&gt;handleRequest($request);
      if ($form-&gt;isSubmitted() &amp;&amp; $form-&gt;isValid()) {
          # search if a prescriber already exists
          $qb = $rp-&gt;createQueryBuilder('p');
          $qb-&gt;where($qb-&gt;expr()-&gt;eq('p.rpps', ':rpps'))
              -&gt;orWhere($qb-&gt;expr()-&gt;andX(
                  $qb-&gt;expr()-&gt;like('p.lastname', ':name'),
                  $qb-&gt;expr()-&gt;like('p.firstname', ':firstname')
              ))
              -&gt;setParameter('rpps', $p-&gt;getRpps())
              -&gt;setParameter('name', '%'.$p-&gt;getLastname().'%')
              -&gt;setParameter('firstname', '%'.$p-&gt;getFirstname().'%');
  
          $duplicates = $qb-&gt;getQuery()-&gt;getArrayResult();
  
          # there are duplicates
          if (!empty($duplicates)) {
              $em-&gt;persist($p);
  
              // confirm the addition of the new prescriber
              $params = array('prescriber' =&gt; $p, 'duplicates' =&gt; $duplicates);
              $query = $request-&gt;query-&gt;all();
              return $this-&gt;forward('AppBundle:Prescriber:addConfirm', $params, $query);
  
          } else {
              $em-&gt;persist($p);       # save the prescriber
              $em-&gt;flush();           # update database
  
              $this-&gt;addFlash('p_success', 'The prescriber has been created successfully');
              return $this-&gt;redirectToRoute('prescriber');
          }
      }
  
      // show form
      return $this-&gt;render('prescribers/form-step1.html.twig', array(
          'form' =&gt; $form-&gt;createView()
      ));
  }
  </code></pre>
  
  <p><strong>addConfirmAction (= step 2)</strong></p>
  
  <pre><code>/**
   * Confirm addition of a new prescriber
   *
   * @Route("/prescribers/add/confirm", name="prescriber_add_confirm")
   */
  public function addConfirmAction(Prescriber $prescriber, $duplicates, Request $request) {
      $em = $this-&gt;getDoctrine()-&gt;getManager();
  
      $form = $this-&gt;createFormBuilder()-&gt;getForm();
  
      if ($form-&gt;handleRequest($request)-&gt;isValid()) {
        $em-&gt;persist($prescriber);
        $em-&gt;flush();
  
        $this-&gt;addFlash('p_success', 'Prescriber has been created successfully');
        return $this-&gt;redirectToRoute('prescriber');
      }
  
      // show confirm page
      return $this-&gt;render('prescribers/form-step2.html.twig', array(
        'h1_title'  =&gt; 'Ajouter un nouveau prescripteur',
        'form'      =&gt; $form-&gt;createView(),
        'p'         =&gt; $prescriber,
        'duplicates'=&gt; $duplicates
    ));
  }
  </code></pre>
  
  <p>I think the problem comes from the fact that I have 2 forms submissions...</p>