Skip to content

Instantly share code, notes, and snippets.

@silenzium
Last active August 29, 2015 14:14
Show Gist options
  • Select an option

  • Save silenzium/87313f71a580510c48fb to your computer and use it in GitHub Desktop.

Select an option

Save silenzium/87313f71a580510c48fb to your computer and use it in GitHub Desktop.

Revisions

  1. silenzium revised this gist Feb 6, 2015. 1 changed file with 5 additions and 4 deletions.
    9 changes: 5 additions & 4 deletions zf2ClearFormErrors
    Original file line number Diff line number Diff line change
    @@ -2,17 +2,18 @@ use Zend\Form\FieldsetInterface;

    /**
    * Remove all errors in a form recursively
    * pass a form or a fieldset as parameter
    *
    * @param FieldsetInterface $fieldset
    * @param FieldsetInterface $form
    * @return void
    */
    public function clearFormErrors(FieldsetInterface $fieldset)
    public function clearFormErrors(FieldsetInterface $form)
    {
    $arr = array();
    foreach($fieldset->getElements() as $element) {
    foreach($form->getElements() as $element) {
    $element->setMessages($arr);
    }
    foreach($fieldset->getFieldsets() as $fieldset) {
    foreach($form->getFieldsets() as $fieldset) {
    $this->clearFormErrors($fieldset);
    }
    }
  2. silenzium created this gist Feb 6, 2015.
    18 changes: 18 additions & 0 deletions zf2ClearFormErrors
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    use Zend\Form\FieldsetInterface;

    /**
    * Remove all errors in a form recursively
    *
    * @param FieldsetInterface $fieldset
    * @return void
    */
    public function clearFormErrors(FieldsetInterface $fieldset)
    {
    $arr = array();
    foreach($fieldset->getElements() as $element) {
    $element->setMessages($arr);
    }
    foreach($fieldset->getFieldsets() as $fieldset) {
    $this->clearFormErrors($fieldset);
    }
    }