PAGES THAT REMEMBER: SIMPLE LOGIN AND MULTIPAGE FORMS (Web server extensions)
PAGES THAT REMEMBER: SIMPLE LOGIN AND MULTIPAGE FORMS 3. Try clicking the Next button in multiple01.php. The form tells you that the name field is missing. Enter anything, and click Next again. The second form asks for Age. Click Next, and the form takes you without complaint to the third page, which asks for Address. This page won t let you get away with entering nothing. Enter anything, and click Send details. You should see something like the following screenshot: Rather than go through the code in detail, I ll leave you to read the inline comments of the four pages. The first three pages use techniques from the rest of this chapter, combined with the form processing techniques from Chapter 5. The main code in the final page looks like this:
The details submitted were as follows:
- $value) { // skip the submit buttons // use identity operator with strpos to prevent false negatives if (strpos($key, ‘Submit’) === 0) { continue; } echo “
- $key: $value
“; } // clear the $_SESSION array and destroy session $_SESSION = array(); session_destroy(); ?>
It cleans up the $_SESSION array by removing $_SESSION[’formStarted’] and session variables created by each of the submit buttons. The name and value of the submit button is always part of the $_POST array, so each submit button is added to $_SESSION array as you progress through the forms. You can skip them in the foreach loop by using strpos() to test for the string Submit. Use the same technique for any other session variables that you want to exclude. 257
We highly recommend you visit web and email hosting services if you need stable and cheap web hosting platform for your web applications.