Zend Form Remove Error Messages

This is post is now quite old and the the information it contains may be out of date or innacurate.

If you find any errors or have any suggestions to update the information please let us know or create a pull request on GitHub

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:

 foreach($subforms['empty'] as $sf){
 	$elements = $sf->getElements();
        foreach($elements as $e){
        	$e->removeDecorator('Errors');
	}
}

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.

public function validateSubForms($data){
	$subforms = $this->getSubForms();
	foreach($subforms as $sf){
		if($sf->isValid($data)){
			$valid[]=$sf;
		}else{
			$error_other_than_empty = false;
			$elements = $sf->getElements();
			foreach($elements as $e){
				$errors = $e->getErrors();
				foreach($errors as $er){
				   // EC_Debug::diedump($er);
					if($er !='isEmpty'){
						$error_other_than_empty = true;
						break(2);
					}
				}
			}
			if($error_other_than_empty){
				$invalid[]=$sf;
			}else{
				$empty[]=$sf;
			}
		}
	}
	return array(
		'valid' => $valid,
		'empty'=>$empty,
		'invalid' => $invalid
	);
}

Tags: zend formzend subformszend form remove error messages