In HTML, setting a form’s
method attribute to
"get" specifies that you would like the form to be submitted using the GET method. When using this method, the form entries are passed as parameters in a URL query string.
For example, this is a request to
www.codecademy.com with the URL parameters
first (set to the value
last (set to the value
The parameter names (
last) come from the
name attribute of each form input.
For example, the following form could be used to collect an individual’s name using the GET method:
<form method="get"> First name: <input type="text" name="first"> <br> Last name: <input type="text" name="last"> <br> <input type="submit" value="Submit Name"> </form>
When the form is submitted, the form data is available in the
$_GET superglobal array. (The data is also accessible using
$_REQUEST if you do not care about which method was used by the client.)
In our example, if a user typed “ellen” into the
first input and “richards” into the
last input, then
print_r($_GET) would look like this:
Array ( [first] => ellen [last] => richards )
We’ve added a form to collect a user’s country and language. Add a
method attribute to the form to specify that you want to use the GET method.
(The default method is actually “get”, but it’s best practice to set this explicitly)
If you try submitting the form, you may notice that the URL is not changing to include URL parameters as you might expect. This is because neither input has a
name attribute yet.
Give the first input a
country and the second input a
Use the PHP shorthand to print the user’s country and language from the
$_GET superglobal array.
You should be replacing the HTML comments that say:
<!--Add step 3 code here-->