Forum Moderators: coopster
if ($_POST) { output_form(null); }
else {
$errors=null;
$errors = check_your_data();
if ($errors) { output_form($errors); }
else {
process_form();
output_response();
}
}
//
function output_form($errorlist=null);
// Here you compose the form, and
if ($errorlist) { $form .= "<ul>$errorlist</ul>"; }
// continue with form
header("content-type:text/html");
echo $form;
exit;
}
//
function check_your_data(); {
$data_errors=null;
// do data checks, if error,
// compile them like so
// $data_errors .= "<li>The email field is required.</li>";
return $data_errors;
}
//
function process_form() {
// update database, send emails, etc.
// No return value unless you need
// more error trapping
}
//
Output your response, no redirect
function output_response () {
header("content-type:text/html");
echo '<p>Success</p>';
exit;
}