PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » HTML » HTML_QuickForm » Bug #2262

regex rule fails on groups

Details

Submitted2004-08-31 19:39 UTC
Fromsean at caedmon dot net
StatusBogus
PackageHTML_QuickForm
PHP VersionIrrelevant
OSN/A
Roadmaps(Not assigned)

Comments

[2004-08-31 19:39 UTC] sean at caedmon dot net

Description:
------------
The regex rule isn't group-aware.
Attached is code to fix this.

LMK if you'd rather a diff.

Actual result:
--------------
/**
* Validates a value using a regular expression
*
* @param string $value Value to be checked
* @param string $regex Regular expression
* @access public
* @return boolean true if value is valid
*/
function validate($value, $regex = null)
{
if (!is_array($value))
{
$value = array($value);
}
foreach ($value AS $val)
{
if (isset($this->_data[$this->name])) {
if (!preg_match($this->_data[$this->name], $val)) {
return false;
}
} else {
if (!preg_match($regex, $val)) {
return false;
}
}
}
return true;
} // end func validate

[2004-09-15 15:57 UTC] sean at caedmon dot net

Uh.. no?

http://pear.php.net/manual/en/package.html.html-quickform.html-quickform.addrule.php

"If the element is in fact a group, it will be considered as a whole, an array of group elements' values will be passed to validation function. To validate grouped elements as separate entities, use addGroupRule()."

I'm complaining that adding a rule doesn't validate the item as a whole.

Either the docs or the code are broken.

S