Our blog

 

Zend Form Remove Error Messages

Sometimes you don't want to display the error messages for a form. I have tried to find the proper solution to remove validtion error messages and haven't found what I would regard as the proper solution.

However what does work for me is to loop through any elements that I want to remove the error messages for and remove the error message decorator like this:

PHP:
  1. foreach($subforms['empty'] as $sf){
  2.     $elements = $sf->getElements();
  3.         foreach($elements as $e){
  4.             $e->removeDecorator('Errors');
  5.     }
  6. }

In this context I have filtered out all the subforms where all inputs are empty and will then remove the error messages from those sub forms.

If you are interested, here is the method I use to validate subforms and separate out valid, invalid and totally empty sub forms.

PHP:
  1. public function validateSubForms($data){
  2.     $subforms = $this->getSubForms();
  3.     foreach($subforms as $sf){
  4.         if($sf->isValid($data)){
  5.             $valid[]=$sf;
  6.         }else{
  7.             $error_other_than_empty = false;
  8.             $elements = $sf->getElements();
  9.             foreach($elements as $e){
  10.                 $errors = $e->getErrors();
  11.                 foreach($errors as $er){
  12.                    // EC_Debug::diedump($er);
  13.                     if($er !='isEmpty'){
  14.                         $error_other_than_empty = true;
  15.                         break(2);
  16.                     }
  17.                 }
  18.             }
  19.             if($error_other_than_empty){
  20.                 $invalid[]=$sf;
  21.             }else{
  22.                 $empty[]=$sf;
  23.             }
  24.         }
  25.     }
  26.     return array(
  27.         'valid' => $valid,
  28.         'empty'=>$empty,
  29.         'invalid' => $invalid
  30.     );
  31. }

More...

More Reading:

 

Leave a Reply