Note that there are some explanatory texts on larger screens.

plurals
  1. POSymfony not displaying errors in twig
    primarykey
    data
    text
    <p>I'm fairly new to Symfony2 framework and I'm having trouble getting errors to display in twig. The constraints are set using <code>$form-&gt;createFormBuilder()-&gt;add()</code></p> <p>When I run <code>{{ form_errors(form) }}</code> nothing displays and I'm not sure what I"m doing wrong.</p> <pre><code>public function massEmailAction(Request $request) { $data['errors'] = ''; $form = array('message'=&gt;'test', 'single_email_val'=&gt;'', 'send_to'=&gt;''); $form = $this-&gt;createFormBuilder($form) -&gt;add('message', 'textarea', array('attr'=&gt;array('style'=&gt;"width: 800px; height: 500px;"))) -&gt;add('single_email_val', 'text', array('label'=&gt;'Single Email', 'required'=&gt;false, 'constraints'=&gt;array( new NotBlank(), new Length(array('min' =&gt; 3)), ), 'invalid_message'=&gt;'email not valid', 'error_bubbling'=&gt;true, )) -&gt;add('send_to', 'choice', array('choices'=&gt;array(''=&gt;'Select', 'single_email'=&gt;'Send to Single Email', 'mass_email'=&gt;'Send to All' ), 'required'=&gt;false, )) -&gt;getForm(); $data['form'] = $form-&gt;createView(); if($request-&gt;isMethod('POST')) { $emailConstraint = new NotBlank(); $formData = $form-&gt;bind($this-&gt;getRequest()); // Get form data $post = $formData-&gt;getData(); echo $post['single_email_val']; if(!$form-&gt;isValid()) { echo 'not valid'; //print_r($this-&gt;getErrorMessages($form)); print_r($this-&gt;getErrorMessages($form)); $data['errors'] = $this-&gt;getErrorMessages($form); // print_r($form-&gt;getErrors()); //echo $form-&gt;getErrorsAsString(); } else { } } return $this-&gt;render('TmarketMarketingBundle:Default:massEmail.html.twig', $data); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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