QF: client-side group rule
| From: | Mark Drago | Date: | Tue, 22 Jun 2004 14:55:05 +0000 |
| Subject: | QF: client-side group rule | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-13244@lists.php.net to get a copy of this message | ||
Hello again,
In my continuing effort to represent an IP address with quickform I have
run into another problem. I am adding 4 text boxes to a group which
will each hold one octet of an IP address. Then, I want to add rules to
it such that each octet must be present, must contain all numbers, must
be between 0 and 255, etc.
I am using the following code to do so:
#create 4 text boxes for ip address
$ip1 = &$this->createElement("text","text1",null,null);
$ip2 = &$this->createElement("text","text2",null,null);
$ip3 = &$this->createElement("text","text3",null,null);
$ip4 = &$this->createElement("text","text4",null,null);
#add text boxes to group
$this->addGroup(array($ip1, $ip2, $ip3, $ip4),"ip_address");
#add required rule
$msg = "Your IP Address was not entered correctly.";
$this->addRule("ip_address",$msg,'required',null,'client');
This generates the javascript, but it never enforces the rule. There
appears to be an error in the javascript. Two stanzas of javascript are
added when this rule is created. The first stanza finds the values for
each of the text boxes and puts them into an array named 'value'. The
next stanza merely checks if value=''. Value is never equal to ''
because value is an array. I saved the page locally and changed the
second stanza to loop over all of the values in the 'value' array and
check each one and I get the correct behavior. Is this an error in QF
or am I using it incorrectly? If it is an error in QF, I can likely
supply a patch to fix it.
--Mark.
--
///////////////////////////////////////////////////////////////
// //
// Mark Drago Phone: 631-434-6600 //
// Associate Software Developer Email: mdrago@bascom.com //
// BASCOM Global Internet Services, Inc. //
// //
///////////////////////////////////////////////////////////////