Issues

ZF-2715: isErrors() in Zend_Form

Issue Type: New Feature Created: 2008-02-22T20:35:31.000+0000 Last Updated: 2008-03-21T16:25:46.000+0000 Status: Resolved Fix version(s): - 1.5.0 (17/Mar/08)

Reporter: Mark Maynereid (mim) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend_Form

Related issues: Attachments:

Description

I would like to display something like:

<pre class="highlight">
<?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:

<pre class="highlight">
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

Posted by Mark Maynereid (mim) on 2008-02-27T09:08:03.000+0000

Oops I think this issue is be bogus.

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

Posted by Mark Maynereid (mim) on 2008-02-27T15:17:22.000+0000

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.

Posted by Matthew Weier O'Phinney (matthew) on 2008-03-05T10:10:22.000+0000

Scheduling for 1.5.0 GA release.

Posted by Matthew Weier O'Phinney (matthew) on 2008-03-06T14:38:27.000+0000

Committed to trunk and release branch.

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts