PHP Lesson 2 - Processing Forms
In this lesson you will learn how to use PHP for processing a form that could be used in real-life scenarios.
Create a Form
Create a Page to Process the Form
Lesson
Lesson Index
Create a Form
- Open the index.php file that you created in lesson 1.
- Erase everything.
- Copy and paste the following into your file and save it.
<form action="form_process.php" method="post">
<input type="text" name="FirstName">
<input type="submit" value="Submit">
<form>
Create a Page to Process the Form
- In the same folder as the index.php file, create a new file called form_process.php.
- Type the following into the new file and save it.
Your first name is <?php echo $_POST['FirstName']; ?>.
Lesson
- Because you typed method="post" in the tag on the first page, whatever you type in and send for the FirstName field gets stored in the php array called $_POST.
- If you type method="get" in the form tag, then the field values will be put into the php variable called $_GET.
- If on the form_process page you don't care whether the field values come through the $_GET or $_POST arrays then you can access them through the php array called $_REQUEST. For example: $_REQUEST['FirstName']. The $_REQUEST array contains any URL parameters, any Form parameters, and any Cookie variables.
Lesson Index
- PHP Lesson 1 - Getting Setup
- PHP Lesson 2 - Procesing Forms
Comments