title: Handle form errors in controller and pass it to twig
body: <p>I'm trying to populate <code>$errors['field_name'] = 'Error message';</code> in my controller so that I can pass the variable to twig for further processing. How can I loop thru the errors and create my own array variable?</p>
  
  <p>I've checked and applied these but didn't get the exact answer, or maybe I missed.</p>
  
  <ul>
  <li><a href="http://knpuniversity.com/blog/symfony-debugging-form-errors" rel="nofollow noreferrer">Accessing and Debugging Symfony Form Errors</a></li>
  <li><a href="https://stackoverflow.com/questions/6978723/symfony2-how-to-get-form-validation-errors-after-binding-the-request-to-the-fo">Symfony2 : How to get form validation errors after binding the
  request to the form</a> (Works but is it reliable?)</li>
  <li><a href="http://shout.setfive.com/2012/02/09/symfony2-getting-all-errors-from-a-form-in-a-controller/" rel="nofollow noreferrer">Symfony2 – Getting All Errors From a Form in a Controller</a> (Overkill)</li>
  </ul>
  
  <p><strong>FORM TYPE</strong></p>
  
  <pre><code>-&gt;add('name', 'text', array('label' =&gt; 'Name', 'error_bubbling' =&gt; true))
  -&gt;add('origin', 'text', array('label' =&gt; 'Origin', 'error_bubbling' =&gt; true))
  </code></pre>
  
  <p><strong>TWIG</strong></p>
  
  <pre><code>{% if errors is defined %}
      &lt;ul&gt;
      {% for field, message in errors %}
          &lt;li&gt;{{ field ~ ':' ~ message }}&lt;/li&gt;
      {% endfor %}
      &lt;/ul&gt;
  {% endif %}
  </code></pre>
  
  <p><strong>CONTROLLER</strong></p>
  
  <pre><code>public function submitAction(Request $request)
  {
      $form = $this-&gt;createForm(new BrandsType(), new Brands());
      $form-&gt;handleRequest($request);
  
      if ($form-&gt;isValid() !== true)
      {
          $errors['field_name'] = 'Error message';
  
          return $this-&gt;render('CarBrandBundle:brands.html.twig',
                  array('errors' =&gt; $errors, 'form' =&gt; $form-&gt;createView()));
      }
  }
  </code></pre>