symfony - Symfony2 form.error field not working -


i got problem. created form class , set asserts entitiy.

but want render errors. got form_erros global erros, not fields.

here code:

controller

public function addaction(request $request){     $news = new news();     $form = $this->createform(new newstype(),$news);      $form->handlerequest($request);      if ($form->isvalid()) {     echo "yepp";     }      return array( 'form' => $form->createview() ); } 

formclass

$builder         ->add('unpublic','checkbox',array(                 'required' => false))         ->add('unactive','checkbox',array(                 'required' => false))         ->add('untitle','text',array(                 'required' => true)) 

view

<div class="form-group">    {{ form_label(form.untitle,'titel*',{ 'label_attr': {'class': 'col-sm-2  control-label'}}) }}     <strong>{{ form_errors(form.untitle) }}</strong>     <div class="col-sm-10">     {{ form_widget(form.untitle, {'attr': {'class' : 'form-control'} })  }}     {{ form_errors(form.untitle) }}     </div> </div> 

entity

/**  * @var string  *  * @orm\column(name="untitle", type="string", length=255)  *   * @assert\notblank()  * @assert\type("text")  *  */ private $untitle; 

thanks lot

as said, {{ form_errors(form) }} displays global form errors, not individual fields.

if want individual field errors accessible via {{ form_errors(form) }}, need enable option error_bubbling => true each single field in form.

others solutions :

  • render each field's error individually {{ form_errors(form.name) }}
  • {{ form_row(form.name) }} render label, widget , errors together.

hope help.


Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -