GINF 5004 Notes

Forms provide a method of retrieving input from the user in HTML. Forms have the following structure:

<form method="POST|GET" action="some cgi script">
	input tags go here.
	Refer to Karthi's notes
</form>

Every form sends information to the server in one of two ways:
POST or GET.

GET was made available in HTTP version 1.0
POST was made available in HTTP version 1.1

The action entry is where you specify the cgi script you want to execute when the form is submitted.
Use the forms below to send information to the following script:

#!/usr/bin/perl -w
 
print "Content-Type: text/plain\n\n";
 
print "This CGI is being executed as:\n";
print "$0\n\n";

print "Query String: $ENV{QUERY_STRING}\n\n";
 
print "You entered the following information:\n";
while (<STDIN>) {
        print;
}
Please input some information on this form (POST):
The script will read the input from this form from STDIN because the form is using the POST method.
Your name:
Your email:
Some info:



Then, try this form (GET):
The script will read the input from this form as command-line arguments or an an environment variable (depending on the web server) because the form is using the GET method.

Your name:
Your email:
Some info:

Perl includes a module called CGI which contructs a hash of the input recieved. This makes life a whole lot easier. Input information on the form below to the following script execute.

#!/usr/bin/perl -w
use CGI;
$q = new CGI;
                                                                                
$name = $q->param("Name");
$email = $q->param("Email");
$text = $q->param("blob");
                                                                                
print "Content-type:text/plain\n\n";
print "You entered the following information:\n";
print "Name = ", $name, "\n"; 
# or print "Name = $name\n";
 
print "Email = ", $email, "\n";
# or print "Email = $email\n";

print "Text = ", $text, "\n";
# or print "Text = $text\n";

The following form uses the GET method:

Your name:
Your email:
Some info:

The following form uses the POST method:

Your name:
Your email:
Some info: