<?
if ($_POST['_submit_check']) {
if (validate_form()) {
process_form();
} else {
show_form();
}
} else {
show_form();
}
function process_form() {
print "Hello, ". $_POST['my_name'];
}
function show_form() {
print<<<_HTML_
<form method="POST" action="$_SERVER[PHP_SELF]">
Your name: <input type="text" name="my_name">
<br/>
<input type="submit" value="Say Hello">
<input type="hidden" name="_submit_check" value="1">
</form>
_HTML_;
}
function validate_form() {
if (strlen($_POST['my_name']) < 3) {
return false;
} else {
return true;
}
}
?>
|