title: Save elements when using the session Symfony
body: <p>I am trying to use the session with Symfony. <br>In fact, I want to complete a form before login. <br> <br>
  For this reason, I would like this scheme:<br></p>
  
  <ol>
  <li>Save the different fields in the session</li>
  <li>Login/register</li>
  <li>Save in the database</li>
  </ol>
  
  <p><br>
  <strong>My controller:</strong> </p>
  
  <pre><code>    public function customMadeAction(Request $request)
      {
          $session = $this-&gt;container-&gt;get('session');
  
          $user = $this-&gt;container-&gt;get('security.context')-&gt;getToken()-&gt;getUser();
  
          $CustomMade = new CustomMade();
          $form = $this-&gt;createForm(new CustomMadeType(), $CustomMade);
  
          $form-&gt;handleRequest($request);
  
          if ($user === 'anon.') {
              if($form-&gt;isValid()) {
  
                  # 1-Save in session
                  var_dump($CustomMade); #I have an array with all I need
                  $session-&gt;set('infos', $CustomMade); #It does not save my informations
  
                  # 2-Redirect to login/register
                  $securityContext = $this-&gt;container-&gt;get('security.context');
                  if (!$securityContext-&gt;isGranted('ROLE_USER')) {
                      throw new AccessDeniedException('Accès refusé');
                  } else {
  
                  # 3-Save in database
                  $em = $this-&gt;getDoctrine()-&gt;getManager();
                  $em-&gt;persist($CustomMade);
                  $em-&gt;flush();
                  }
              }
          }else{
              if($form-&gt;isValid()) {
                  $CustomMade-&gt;setIdUser($user-&gt;getId());
                  $em = $this-&gt;getDoctrine()-&gt;getManager();
                  $em-&gt;persist($CustomMade);
                  $em-&gt;flush();
              }
          }
          return $this-&gt;render('FrontBundle:Forms:customMade.html.twig', array(
              'form' =&gt; $form-&gt;createView()
          ));
      }
  </code></pre>