[icinga-checkins] icinga.org: icingaweb2/feature/redesign-7144: Number element: Use is_numeric in favor of Zend's float validator

git at icinga.org git at icinga.org
Tue Nov 18 16:36:34 CET 2014


Module: icingaweb2
Branch: feature/redesign-7144
Commit: e3629a7f41b6e726766e6400984c9efc2c6b59f2
URL:    https://git.icinga.org/?p=icingaweb2.git;a=commit;h=e3629a7f41b6e726766e6400984c9efc2c6b59f2

Author: Eric Lippmann <eric.lippmann at netways.de>
Date:   Tue Nov 18 10:29:28 2014 +0100

Number element: Use is_numeric in favor of Zend's float validator

The float validator uses Zend_Locale which we have stripped in our vendor library thus leading to erroneous validation.
Further we'll use php-intl instead of Zend_Locale one day :)

fixes #7692

---

 library/Icinga/Web/Form/Element/Number.php |   16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/library/Icinga/Web/Form/Element/Number.php b/library/Icinga/Web/Form/Element/Number.php
index 8361425..02f0aaa 100644
--- a/library/Icinga/Web/Form/Element/Number.php
+++ b/library/Icinga/Web/Form/Element/Number.php
@@ -47,7 +47,6 @@ class Number extends FormElement
      */
     public function init()
     {
-        $this->addValidator('Float', true);  // true for breaking the validator chain on failure
         if ($this->min !== null) {
             $this->addValidator('GreaterThan', true, array('min' => $this->min));
         }
@@ -127,4 +126,19 @@ class Number extends FormElement
     {
         return $this->step;
     }
+
+    /**
+     * (non-PHPDoc)
+     * @see \Zend_Form_Element::isValid() For the method documentation.
+     */
+    public function isValid($value, $context = null)
+    {
+        $this->setValue($value);
+        $value = $this->getValue();
+        if (! is_numeric($value)) {
+            $this->addError(sprintf($this->translate('\'%s\' is not a valid number'), $value));
+            return false;
+        }
+        return parent::isValid($value, $context);
+    }
 }



More information about the icinga-checkins mailing list