ZF-2715: isErrors() in Zend_Form

Description

I would like to display something like:


<?if ($this->form->isErrors()):?>

Errors were found in your input. Please see below for details.

<?endif;?>

I find a high number of people don't even register an input error has occurred unless you make it clear at the very top of the page. For various reasons they may have scrollbars if the form is a little long or they have their window shrunk, run on a low res, use WAP hell I don't know :) But I found the form error rate is helped by placing a big notice at the top of the page. Seems reasonable to ask the form about this. I realise isValid() insists on the data being passed and I think I understand why so. Here's lighter suggestion to achieve this:


Index: Form.php
===================================================================
--- Form.php    (revision 8325)
+++ Form.php    (working copy)
@@ -112,6 +112,12 @@
     protected $_isArray = false;

     /**
+     * Records the result of the last validation
+     * @var bool
+     */
+    protected $_isErrors;
+
+    /**
      * Form legend
      * @var string
      */
@@ -1673,6 +1679,7 @@
                 }
             }
         }
+        $this->_isErrors = ! $valid;
         return $valid;
     }

@@ -1724,10 +1731,21 @@
                 }
             }
         }
+        $this->_isErrors = ! $valid;
         return $valid;
     }

     /**
+     * Report error state resulting from the last validation
+     *
+     * @return boolean|null
+     */
+    public function isErrors()
+    {
+        return $this->_isErrors;
+    }
+
+    /**
      * Process submitted AJAX data
      *
      * Checks if provided $data is valid, via {@link isValidPartial()}. If so,

Comments

Oops I think this issue is be bogus.

Simply calling if ($this->form->getErrors())... provides what I was looking for.

Spoke too soon. Not sure if it's due to an svn update or I just didn't check it out properly enough but getErrors() when there are no errors returns an array of empty arrays and so is not suitable for an if (...) test.

Scheduling for 1.5.0 GA release.

Committed to trunk and release branch.