Save form data to session, repopulate form with it on refresh (Symfony)
<p>I'm willing to save a form (created with FormBuilder) on submit to the session. As soon as the user comes back to the same page, the form should be repopulated with the previous submitted information in case it exist. </p>

<pre><code>    // Create form
    $form = $this-&gt;createForm(MappingType::class, $mapping);
    $form-&gt;handleRequest($request);

    // Populate it if we already have data from the request or from session, only when not submitted
    if (!$form-&gt;isSubmitted() &amp;&amp; $request-&gt;getSession()-&gt;has('mapping')) {
       $form-&gt;setData($request-&gt;getSession()-&gt;get('mapping'));
    }

    // Save form data to session
    if ($form-&gt;isSubmitted() &amp;&amp; $form-&gt;isValid()) {
        $request-&gt;getSession()-&gt;set('mapping', $form-&gt;getData());
    }
</code></pre>

<p>The MappingType form is with children, but also a field on top level doesn't seem to get populated again. The Children mainly consist of ChoiceType fields.</p>

<p>The session data is populated with all form data. And as I'm not using Doctrine, but just a plain entity, I see no issues with persistence.</p>

<p>The form gets populated correctly on the POST request (handleRequest), but not when I just load it again (GET).</p>

<p>Any ideas?</p>