Req #19302 [Opn->WFx]: add 2 new rules (integer and numeric)

From: Date: Thu, 23 Feb 2012 10:28:03 +0000
Subject: Req #19302 [Opn->WFx]: add 2 new rules (integer and numeric)
References: 1  Groups: php.pear.bugs 
Request: Send a blank email to pear-bugs+get-8308@lists.php.net to get a copy of this message
Edit report at https://pear.php.net/bugs/bug.php?id=19302&edit=1 ID: 19302 Updated by: borz_off@cs.msu.su Reported By: gregory_jarrige at yahoo dot fr Summary: add 2 new rules (integer and numeric) -Status: Open +Status: Wont fix Type: Feature/Change Request Package: HTML_QuickForm2 Operating System: Zend Server on Windows & IBM i Package Version: 0.6.1 PHP Version: 5.3.5 Roadmap Versions: New Comment: -Status: Open +Status: Wont fix While such rules may indeed make sense, the implementations are subpar. Server-side they are equivalent to $element->addRule('callback', 'an error message', array( 'callback' => 'filter_var', 'arguments' => FILTER_VALIDATE_INT )); and don't have client-side implementations at all (note that we have these for all built-in rules). Previous Comments: ------------------------------------------------------------------------ [2012-02-22 16:40:12] gregj Description: ------------ Hello, I would be interested if you could add 2 new rules in HTML Quickform2, because they're very practical for projects that I develop. I propose to you an example of code (it's the patch that I use for the moment). Best regards, Gregory Jarrige Test script: --------------- class HTML_QuickForm2_Rule_Integer extends HTML_QuickForm2_Rule { protected function validateOwner() { $value = $this->owner->getValue(); if (filter_var($value, FILTER_VALIDATE_INT) === false) { return false; } else { return true; } } } class HTML_QuickForm2_Rule_Numeric extends HTML_QuickForm2_Rule{ protected function validateOwner() { $value = $this->owner->getValue(); if (filter_var($value, FILTER_VALIDATE_FLOAT) === false) { // convert "french" numeric format to US format $value = str_replace('.', '', strval($value)) ; $value = str_replace(',', '.', $value) ; if (filter_var($value, FILTER_VALIDATE_FLOAT) === false) { $answer = false ; } else { $answer = true ; } } else { $answer = true ; } return $answer ; } } ------------------------------------------------------------------------ -- Edit this bug report at https://pear.php.net/bugs/bug.php?id=19302&edit=1

« previous php.pear.bugs (#8308) next »