cvs: pear /HTML_QuickForm QuickForm.php /HTML_QuickForm/QuickForm Validate.php

From: Date: Tue, 16 Sep 2003 14:32:19 +0000
Subject: cvs: pear /HTML_QuickForm QuickForm.php /HTML_QuickForm/QuickForm Validate.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-12775@lists.php.net to get a copy of this message
mansion Tue Sep 16 10:32:19 2003 EDT Modified files: /pear/HTML_QuickForm QuickForm.php /pear/HTML_QuickForm/QuickForm Validate.php Log: Allow validation of group values altogether in an array when the rule is set using addRule() instead of addGroupRule(). addGroupRule() will validate the group values one by one. Index: pear/HTML_QuickForm/QuickForm.php diff -u pear/HTML_QuickForm/QuickForm.php:1.116 pear/HTML_QuickForm/QuickForm.php:1.117 --- pear/HTML_QuickForm/QuickForm.php:1.116 Tue Aug 26 13:45:43 2003 +++ pear/HTML_QuickForm/QuickForm.php Tue Sep 16 10:32:18 2003 @@ -17,7 +17,7 @@ // | Bertrand Mansion <bmansion@mamasam.com> | // +----------------------------------------------------------------------+ // -// $Id: QuickForm.php,v 1.116 2003/08/26 17:45:43 avb Exp $ +// $Id: QuickForm.php,v 1.117 2003/09/16 14:32:18 mansion Exp $ require_once('PEAR.php'); require_once('HTML/Common.php'); @@ -888,9 +888,6 @@ 'validation' => $validation, 'reset' => $reset); - if ($type != 'function' && $this->getElementType($element) == 'group') { - $rule['howmany'] = 1; - } $this->_rules[$element][] = $rule; } // end func addRule @@ -1419,7 +1416,11 @@ // Element is not required continue 2; } - $result = $validate->validate($rule['type'], $submitValue, $rule['format']); + if (is_array($submitValue) && !isset($rule['howmany'])) { + $result = $validate->validate($rule['type'], $submitValue, $rule['format'], true); + } else { + $result = $validate->validate($rule['type'], $submitValue, $rule['format'], false); + } if ($result === false || (!empty($rule['howmany']) && $rule['howmany'] > (int)$result)) { if (isset($rule['group'])) { Index: pear/HTML_QuickForm/QuickForm/Validate.php diff -u pear/HTML_QuickForm/QuickForm/Validate.php:1.1 pear/HTML_QuickForm/QuickForm/Validate.php:1.2 --- pear/HTML_QuickForm/QuickForm/Validate.php:1.1 Thu Aug 21 09:05:16 2003 +++ pear/HTML_QuickForm/QuickForm/Validate.php Tue Sep 16 10:32:19 2003 @@ -18,20 +18,20 @@ // | Bertrand Mansion <bmansion@mamasam.com> | // +----------------------------------------------------------------------+ // -// $Id: Validate.php,v 1.1 2003/08/21 13:05:16 mansion Exp $ +// $Id: Validate.php,v 1.2 2003/09/16 14:32:19 mansion Exp $ $GLOBALS['_HTML_QuickForm_registered_rules'] = array( 'required' => array('html_quickform_rule_required', 'HTML/QuickForm/Rule/Required.php'), - 'maxlength' => array('html_quickform_rule_range', 'HTML/QuickForm/Rule/Range.php'), - 'minlength' => array('html_quickform_rule_range', 'HTML/QuickForm/Rule/Range.php'), - 'rangelength' => array('html_quickform_rule_range', 'HTML/QuickForm/Rule/Range.php'), - 'email' => array('html_quickform_rule_email', 'HTML/QuickForm/Rule/Email.php'), - 'regex' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'), - 'lettersonly' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'), - 'alphanumeric' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'), - 'numeric' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'), - 'nopunctuation' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'), - 'nonzero' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'), + 'maxlength' => array('html_quickform_rule_range', 'HTML/QuickForm/Rule/Range.php'), + 'minlength' => array('html_quickform_rule_range', 'HTML/QuickForm/Rule/Range.php'), + 'rangelength' => array('html_quickform_rule_range', 'HTML/QuickForm/Rule/Range.php'), + 'email' => array('html_quickform_rule_email', 'HTML/QuickForm/Rule/Email.php'), + 'regex' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'), + 'lettersonly' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'), + 'alphanumeric' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'), + 'numeric' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'), + 'nopunctuation' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'), + 'nonzero' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'), 'callback' => array('html_quickform_rule_callback', 'HTML/QuickForm/Rule/Callback.php') ); @@ -138,21 +138,22 @@ * @param mixed $values Can be a scalar or an array of values * to be validated * @param mixed $options Options used by the rule + * @param mixed $multiple Whether to validate an array of values altogether * @access public * @return mixed true if no error found, int of valid values (when an array of values is given) or false if error */ - function validate($ruleName, $values, $options = null) + function validate($ruleName, $values, $options = null, $multiple = false) { $rule =& $this->getRule($ruleName); - if (is_array($values)) { - $result = 0; - foreach ($values as $value) { - if ($rule->validate($value, $options) === true) { - $result++; - } - } - return ($result == 0) ? false : $result; + if (is_array($values) && !$multiple) { + $result = 0; + foreach ($values as $value) { + if ($rule->validate($value, $options) === true) { + $result++; + } + } + return ($result == 0) ? false : $result; } else { return $rule->validate($values, $options); }

« previous php.pear.cvs (#12775) next »