Most often, web pages use HTML forms for user input. It is very important to validate user input before storing it in a database or other types of processing
lab7input.php
web page, use an XHTML Form with input widgets to allow the user to
lab7input.php
lab7validate.php
Web page, use PHP to validate the user input, displaying error message is there is a problem or displaying the user input if everything is correct
validate_input()
that returns a string containing any error messages or an empty string if the user input completely validatesNote: All HTML elements are laid out using the default browser styling. Inline elements are enclosed inside paragraphs <p>
lab7input.php
lab7validate.php
A better approach to handling PHP user input validation is to do it all-in-one-page: user input, validation, and processing.
The overall logic to implement all-in-one-page processing is
Modify lab7input.php
to do all-in-one-page processing: prompt for input, validate, and process the data (minimally)
validate_input()
into the start of lab7input.php
action
attribute of the PHP form to call itself (action="")if else
logic to take all-in-one-page approach to processing (Code given below)The simplified processing of the data above is to save the user's name as a session variable to re-display on the confirmation page: thankyou.php
To use session variables on the lab machines, we need to reset the session save path to C:\wamp\www\labs\sessiondata (as well as creating the subfolder sessiondata)
lab7input.php
thankyou.php
page that displays the welcome message: Thank you name, getting name from the SESSION variable set in lab7input.phpIn order to re-show the form with user input still present, use the input element's value attribute set to the contents of the appropriate $_POST variable. For example,