symfony - In symfony2 is there a single variable or methode like 'hasError' to check if a form returns any errors? -


in symfony can link validation both field or input errors returned in form.vars.error , form.fielname.vars.errors

in template had these checks fuigure out if form return error on of fields

{% set oneormorefieldsempty = form.title.vars.value == ''         or form.location.vars.value == ''         or form.zip.vars.value == ''         or form.city.vars.value == ''         or form.address.vars.value == ''         or form.description.vars.value == ''         or form.type.vars.value == ''         or form.dresscode.vars.value == ''         or (form.registrationtypemember.vars.value == 2 , form.costmember.vars.value == '')         or (form.guestallowed.vars.value == 1 , form.guestperparticipant.vars.value empty )         or (form.targetagegroup.vars.value == 1 , (form.agemin.vars.value == '' or form.agemax.vars.value == ''))         or (form.numberofplaceslimited.vars.value == 1 , form.maxtotalparticipant.vars.value == '') %}  {% set oneormorefieldsinvalid = (form.title.vars.value != '' , form.title.vars.errors|length > 0)         or (ninvalidfields > 0  )         or (form.startat.vars.errors|length > 0)         or (form.endat.vars.errors|length > 0)         or (form.location.vars.value != '' , form.location.vars.errors|length > 0)         or (form.zip.vars.value != '' , form.zip.vars.errors|length > 0)         or (form.city.vars.value != '' , form.city.vars.errors|length > 0)         or (form.description.vars.value != '' , form.description.vars.errors|length > 0)         or (form.type.vars.value != '' , form.type.vars.errors|length > 0)         or (form.dresscode.vars.value != '' , form.dresscode.vars.errors|length > 0)         or (form.registrationtypemember.vars.value == 2 , form.costmember.vars.value != '' , form.costmember.vars.errors|length > 0)          or (form.guestallowed.vars.value == 1 , not(form.guestperparticipant.vars.value empty) , form.guestperparticipant.vars.errors|length > 0)         or (form.targetagegroup.vars.value == 1 , form.agemin.vars.value != '' , form.agemax.vars.value != '' , (form.agemin.vars.errors|length>0 or form.agemax.vars.errors|length>0 or form.targetagegroup.vars.errors|length>0))         or (form.numberofplaceslimited.vars.value == 1 , not(form.maxtotalparticipant.vars.value empty) , form.maxtotalparticipant.vars.errors|length > 0) %}  {% if (haserrors == true , ( oneormorefieldsempty or oneormorefieldsinvalid ) ) %}             <div class="notice error" >                 {% if (oneormorefieldsempty) %}                      <div>{{ 'create.msg.emptyfields'|trans({},'activity')|raw }}</div>                 {% endif %}                  {% if (ninvalidfields>0) %}                     <div>{{ 'create.msg.invalidfields'|trans({},'activity')|raw }}</div>                 {% endif %}             </div> {% endif %} 

all these lines display single generic message @ beginning of form , display later in form appopriate error beneath field input.

pretty scary right ?

so there way check if form returns errors on both form or fields ?

thanks in advance

you have add method in controller or in super controller:

protected function geterrormessages(\symfony\component\form\form $form) {     $errors = array();      if ($form->haschildren()) {         foreach ($form->getchildren() $child) {             if (!$child->isvalid()) {                 $errors[$child->getname()] = $this->geterrormessages($child);             }         }     } else {         foreach ($form->geterrors() $key => $error) {             $errors[] = $error->getmessage();         }     }      return $errors; } 

Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -