HTML_QuickForm - Required : bug in validator?
| From: | Noel da Costa | Date: | Sat, 21 Jul 2007 08:57:51 +0000 |
| Subject: | HTML_QuickForm - Required : bug in validator? | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-27710@lists.php.net to get a copy of this message | ||
Hi,
I'm wondering if this is a bug or perhaps a case of me mis-using the "Required" rule...
When validating a drop-down or multi-select, I use the Quickform AddRule with the callback argument to call a custom validator. All good, but I also want the drop-down to appear as a required field with the little star and all... so I generally add the Required rule to get this working. The trouble comes when the value returned is an array instead of a string.. the required rule coughs up a fatal error.
I'm wondering:
a) Is there a better way of marking my custom validated drop-downs as required?
b) If not can I recommend the following patch (and how do I do so through the proper channels).
class HTML_QuickForm_Rule_Required extends HTML_QuickForm_Rule
{
/**
* Checks if an element is empty
*
* @param string $value Value to check
* @param mixed $options Not used yet
* @access public
* @return boolean true if value is not empty
*/
function validate($value, $options = null)
{
if (is_array($value))
{
foreach($value as $key=>$val)
{
if((string)$val == '')return false;
}
} else {
if ((string)$value == '') {
return false;
}
}
return true;
} // end func validate
...
}
Thanks!
Noel da Costa
Lead Developer
Magnet Harlequin
T: 01895 432400
M: 07879 427940
F: 01895 432444
E: noel.dacosta@magharl.co.uk
W: http://www.magharl.co.uk
This e-mail is intended solely for the addressees named above and any other
use is prohibited. Access to this email by anyone else is unauthorised. It
may contain confidential information. If you have received this e-mail in
error, please contact the sender by return e-mail. We do not accept legal
responsibility for the contents of this message if it has reached you via
the internet. Any opinions expressed are those of the author and are not
necessarily endorsed by the company. Recipients are advised to apply their
own virus check to this message and all incoming e-mail on delivery.