Use a hidden parameter to indicate form submission in PHP

Description

The following code shows how to use a hidden parameter to indicate form submission.

Example


<?//from   w w  w  .ja  va 2  s.c  om
if ($_POST['_submit_check']) {
    process_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_;
}
?>

The code above generates the following result.

Use a hidden parameter to indicate form submission in PHP




















Home »
  PHP Tutorial »
    Form »




PHP Form
Form Demo