if ($_POST['_submit_check']) {
if ($form_errors = validate_form()) {
show_form($form_errors);
} else {
process_form();
}
} else {
show_form();
}
function process_form() {
print "Hello, ". $_POST['my_name'];
}
function show_form($errors = '') {
if ($errors) {
print 'Please correct these errors: - ';
print implode(' - ', $errors);
print '
';
}
print<<<_HTML_
_HTML_;
}
function validate_form() {
$errors = array();
if (strlen($_POST['my_name']) < 3) {
$errors[] = 'Your name must be at least 3 letters long.';
}
return $errors;
}
?>