title: Symfony 2.6 form validation and error messages
body: <p>I am fairly new to Symfony. I have written the below code to validate and return error messaged if validation failed. But I was able to only get the error message not the field which failed the validation. Below is my code:</p>
  
  <pre><code>if ($request-&gt;isXmlHttpRequest()) {
  
          if ($form-&gt;isValid()) {
              //do something here
          }
  
          $errors = $this-&gt;get('my_form')-&gt;getErrorMessages($form);
          return new JsonResponse(['errors' =&gt; $errors], 400);
  }
  </code></pre>
  
  <p>Can someone please tell me how can I also get the field name along with the error message.</p>
  
  <p>Thanks</p>