Exercise - The GET method
Use html to build a web page containing a form with
Give the textarea the name meaning and the text input the name firstname
Change the line with the opening <form> tag to read,
<form name='mysurvey' action='cgi-bin/mysurvey.pl' method='get'>
The ACTION attribute tells the form which cgi script to send the data to.
The METHOD attribute tells the server to use the GET method, there are others
will look at shortly.
Save your file as survey1.html in your public_html directory.
Now you can write the perl script.
#!/usr/bin/perl
$formdata=$ENV{'QUERY_STRING'};
print "Content-type:text/html","\n\n";
print $formdata, "\n";
In this script we are
Save your script as mysurvey.pl in your cgi-bin directory.
Run your html page and press the Submit button.
If all went according to plan you should have something that looks like this
firstname=yourname&meaning=to+avoid+death
Yep that's one big string with spaces replaced by + signs.
Later will we see how to break this down or parse it into its components.
When you use the GET method the browser takes the following steps
all the data is added it to the end of the url.
This is called URL encoding.
The browser pairs up the key name and its value with an = sign, these are called the key-value pairs,
The key-values are then combined with &'s.
Finally any non alpha-numeric characters are replaced with their hexadecimal equivalent.
For example if we were to send an url via a form the part http:// would be sent
as http%3A%2F%2F