May 2003
Intermediate to advanced
592 pages
14h 28m
English
All of the examples in this chapter and the previous one used two separate scripts for handling HTML forms: one that displayed the form and another that received it. While there’s certainly nothing wrong with this method, there are advantages to having the entire process in one script. To have one page both display and handle a form, use a conditional.
if (/* form has been submitted */) {
// Handle it.
} else {
// Display it.
To determine if the form has been submitted, I normally check if the $submit variable is set (which is the name of the submit input type in the form).
if (isset($_POST['submit'])) {
// Handle it.
} else {
// Display it.
echo '<input type="submit" name="submit" value="Go!">';
}
If you ...
Read now
Unlock full access