a page processes date from a form, if there are any errors, such as missing fields it sets an error code in an array, if there was an array the session, formerror is set to the error array,. The error array starting out as
$errorArray = array("itemid" => 0,"itemdate" => 0,"itemuser" => 0,"itemtype" => 0,"itemheadline" => 0,"actiontype" => 0);
and having error codes set if an error is encountered. once the error checking is done the script runs this:
/*
foreach($errorArray as $key => $value) {
//if ((1 === $value) or (2 === $value)) {
if (($value == 1) or ($value == 2)) {
$_SESSION["formerror"] = $errorArray;
$_SESSION["formaction"] = $itemAction;
header("Location:index.php?id=edititemform");
exit;
}
}
*/
//LOL, could have used in_array...
if ((in_array(1, $errorArray) or (in_array(2, $errorArray))) {
$_SESSION["formerror"] = $errorArray;
$_SESSION["formaction"] = $itemAction;
header("Location:index.php?id=edititemform");
exit;
}
//Much better
So if an error was set (1 or 2) then the form processing will be stopped and the user sent back to the form page, the form page then populated with the respecive errors.
So back to the form it goes...
...
$errorArray = array ();
if (isset($_SESSION["formerror"])) {
$errorArray = $_SESSION["formerror"];
foreach($errorArray as $key => $value) {
echo "Error code for $key = $value<br />";
$keyclass = $key . "class";
if ($value == 0) {
//Tick Icon
$$keyclass = "formicon0";
} elseif ($value == 1) {
//Required Icon
$$keyclass = "formicon1";
} else {
//Error Icon
$$keyclass = "formicon2";
}
}
unset($_SESSTION["formerror"]);
}
...
yes i am session_start();