Date: 11/11/99
- Next message: Eric Thelin: "[PHPLIB] Re: Multiple database problems"
- Previous message: Alan Lee: "[PHPLIB] altering validate()"
- Maybe in reply to: Alan Lee: "[PHPLIB] altering validate()"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
If you want to tell your users which element of an array valued form
input was invalid, here's how.
Edit of_text.inc
copy the entire function self_validate(), then:
function self_validate($val) {
if (!is_array($val)) $val = array($val);
else return $this->array_self_validate($val); /* add this line */
// } // end TEXT /* comment out this
line */
then paste in the function you copied, changing it's name:
function array_self_validate($val) { /* change the name */
reset($val);
$i = 0; /* add this line for a
counter */
while (list($k,$v) = each($val)) {
$i++; /* add this line to
count */
if ($this->length_e && (strlen($v) < $this->minlength))
return array($i, $this->length_e); /* return an array for
yourself */
if ($this->valid_e && (($this->icase &&
!eregi($this->valid_regex,$v)) ||
(!$this->icase &&
!ereg($this->valid_regex,$v))))
return array($i, $this->valid_e); /* return another
array for yourself */
}
return false;
}
} // end TEXT
Now in your web document, after you do $err = $f->validate();
you can do:
if($err) echo "Section $err[0]: $err[1]";
which will come out: "Section 4: That input is no good. Do again!"
A.
-
PHP3 Base Library Mailing List. Send messages to <phplib <email protected>>.
To unsubscribe, send "unsubscribe" to <phplib-request <email protected>> in
the body, not the subject, of your message.
- Next message: Eric Thelin: "[PHPLIB] Re: Multiple database problems"
- Previous message: Alan Lee: "[PHPLIB] altering validate()"
- Maybe in reply to: Alan Lee: "[PHPLIB] altering validate()"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

