Note that there are some explanatory texts on larger screens.

plurals
  1. POHandle two forms in one Controller with Symfony2
    text
    copied!<p>Hey I am saving every page in two different languages on my website. I want to manage my pages with an admin area that I am developing with symfony2 at the moment.</p> <p>Following controller code is able to display two forms on the same page containing the right data from the database. One form to manage the DE language and another for EN:</p> <p>View:</p> <pre><code>&lt;form action="{{ path('admin_about') }}" method="post" {{ form_enctype(formEN) }}&gt; {{ form_widget(formEN) }} &lt;button type="submit" class="btn btn btn-warning" naem="EN"&gt;Save&lt;/button&gt; &lt;/form&gt; &lt;form action="{{ path('admin_about') }}" method="post" {{ form_enctype(formDE) }}&gt; {{ form_widget(formDE) }} &lt;button type="submit" class="btn btn btn-warning" name="DE"&gt;Save&lt;/button&gt; &lt;/form&gt; </code></pre> <p>Controller: public function aboutAction(Request $request) {</p> <pre><code> $pageEN = $this-&gt;getDoctrine() -&gt;getRepository('MySitePublicBundle:Page') -&gt;findOneBy(array('idName' =&gt; 'about', 'lang' =&gt; 'EN')); $pageDE = $this-&gt;getDoctrine() -&gt;getRepository('MySitePublicBundle:Page') -&gt;findOneBy(array('idName' =&gt; 'about', 'lang' =&gt; 'DE')); if (!$pageDE) { throw $this-&gt;createNotFoundException('About page (DE) not found.'); } if (!$pageEN) { throw $this-&gt;createNotFoundException('About page (EN) not found.'); } $formDE = $this-&gt;createFormBuilder($pageDE) -&gt;add('title', 'text') -&gt;add('content', 'text') -&gt;getForm(); $formEN = $this-&gt;createFormBuilder($pageEN) -&gt;add('title', 'text') -&gt;add('content', 'text') -&gt;getForm(); //Save Form here return $this-&gt;render('MySitePublicBundle:Admin:about.html.twig', array( 'aboutPageDE' =&gt; $pageDE, 'aboutPageEN' =&gt; $pageEN, 'formDE' =&gt; $formDE-&gt;createView(), 'formEN' =&gt; $formEN-&gt;createView(), )); } </code></pre> <p><strong>My Question is: How to save the form that has been used out of one controller?</strong> </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload