Skip to content

Instantly share code, notes, and snippets.

@silenzium
Last active August 29, 2015 14:14
Show Gist options
  • Save silenzium/87313f71a580510c48fb to your computer and use it in GitHub Desktop.
Save silenzium/87313f71a580510c48fb to your computer and use it in GitHub Desktop.
ZF2 helper function to remove all errors in a form or fieldset recursively
use Zend\Form\FieldsetInterface;
/**
* Remove all errors in a form recursively
* pass a form or a fieldset as parameter
*
* @param FieldsetInterface $form
* @return void
*/
public function clearFormErrors(FieldsetInterface $form)
{
$arr = array();
foreach($form->getElements() as $element) {
$element->setMessages($arr);
}
foreach($form->getFieldsets() as $fieldset) {
$this->clearFormErrors($fieldset);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment