benifactor wrote:

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?

Well, the only real *variable* datum there is which condition
was broken.  So, how about leaving out the HTML construction
until after the determination has been made?

HTH,

KDK

--
QOTD:
        Money isn't everything, but at least it keeps the kids in touch.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to