PHP: Using hidden parameters to test for form submission

This entry is part 40 of 54 in the series PHP Tutorial

Another technique for testing form submission is to use hidden parameters. If the hidden parameter is in $_POST , then we process the form.

<input type='hidden' name='submit_check' value='1'>

The hidden parameter is shown in line 25 and there is a type=’hidden’ in the parameter.


// Logic to do the right thing based on
// the hidden _submit_check parameter
if ($_POST['submit_check']) {
} else {

// Do something when the form is submitted
function process_form()
    print 'Hello, ' . $_POST['my_name'];

// Display the form
function show_form()
    print<<< html_output
<form method='POST' action='$_SERVER[PHP_SELF]'>
Your name: <input type='text' name='my_name'>
<input type='submit' value='Say Hello'>
<input type='hidden' name='submit_check' value='1'>

Series Navigation<< PHP: Form processing with functions
PHP: A simple form with validation >>