any better way...
| From: | benifactor | Date: | Fri, 21 Apr 2006 02:52:01 +0000 |
| Subject: | any better way... | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-234452@lists.php.net to get a copy of this message | ||
I am trying to come up with the best way to check for errors on a form. I have done this before by
checking each $_POST variable seperatly but needed a better way that would display more then one
error. The following is what i came up with...
if (!$condition1 || !$condition2 || $condition1 != $condition2) {
if (!$condition1) {
$regError[0] = "condition 1 not met.";
$regErrorc[0] = "<font color=red>";
$regErrore[0] = "</font>";
$regErrord[0] = "<font color=red>***</font>";
}
else {
if (!$condition2) {
$regError[1] = "condtion 2 not met.";
$regErrorc[1] = "<font color=red>";
$regErrore[1] = "</font>";
$regErrord[1] = "<font color=red>***</font>";
}
else {
if ($condition1 != $condition2) {
$regError[0] = "condition 1 is not equal to condition 2";
$regErrorc[0] = "<font color=red>";
$regErrore[0] = "</font>";
$regErrord[0] = "<font color=red>***</font>";
$regErrorc[1] = "<font color=red>";
$regErrore[1] = "</font>";
$regErrord[1] = "<font color=red>***</font>";
}
}
}
}
which works fine but gets rather lengthy... i was just wondering if there is any better logic to
go about this with and if there is could you please enlighten me?