 validate and redirect before echoing anything...
A good practice for form validations would be to run the validations before displaying the form or any echo statements.
<?php
if (isset($_POST)) {
// only if post has been set run the validations:
// validation code would go here. example:
if (!empty($_POST['somevalue'])) {
$value = TRUE;
} else {
$errorArray[] = "This value wasn't submitted properly";
$value = FALSE;
}
// once the validations are done, check all of the values in case some failed.
if ($value1 && $value2 && $value3) {
// everything passed, redirect the user!
header(Location: thankyou.php);
exit(); // call this to kill the script at this point
} else {
// there were some errors, loop through the $errorsArray to display the errors.
foreach ($errorArray as $errorValue) {
echo "$errorValue <br />";
}
}
}
// now display the form, since the script made it this far, $_POST hasn't been set yet.
?>
<!-- HTML AND FORM GOES HERE -->
_________________ somewhere a clock is ticking...
|