In HTML, setting a form’s method
attribute to "post"
specifies that you would like the form to be submitted using the POST method. When using POST to submit forms, you will not see the URL change. The form data is sent using the headers of the HTTP request instead of URL parameters.
To use the data from the form in PHP, each input needs to have a unique name
attribute.
When the form is submitted, the input data is available in the $_POST
superglobal. Similar to GET, it is also available in $_REQUEST
.
For example, if a user typed “Katharine” into the first
input and “McCormick” into the last
input of this form:
<form method="post"> First name: <input type="text" name="first"> <br> Last name: <input type="text" name="last"> <br> <input type="submit" value="Submit Name"> </form>
The URL would not change and print_r($_POST)
would look like this:
Array ( [first] => Katharine [last] => McCormick )
Instructions
We’ve added a form to collect a user’s favorite food and color. Add a method attribute to the form to specify that you want to use the POST method.
To use the inputs in PHP, they need to have names.
Give the first input a name
of color
and the second input a name
of food
.
Use the PHP shorthand to print the user’s favorite food and color from the $_POST superglobal array.
You should be replacing the HTML comments that say:
<!--Add step 3 code here-->