previous | start

Example CGI

Using the following HTML:
<html>
<head>
<TITLE>Test form for INT20CN Lecture #22 Example</TITLE>
</head>
<body bgcolor="#FFFFFF">

<h2>Test form for INT20CN Lecture #22 Example</h2>
<FORM action="/subjects/bitcne/cgi/L22CGI.cgi" method="GET">
Family Name: <INPUT type="text" name="family" size="20"><br>
Given Name: <INPUT type="text" name="given" size="20"><br>
<input type="submit" value="Get Information">
<input type="reset" value="Clear Form">
</FORM>
</BODY>
</HTML>
The <FORM> markup of this segment of HTML looks like:
Family Name
Given Name
Note that you can press the "submit" button if you like...
 
This <FORM> is processed by the following CGI program (in Perl):
#!/usr/local/bin/perl
use CGI;

$fdata = CGI->new();
$family = $fdata->param("family");
$given = $fdata->param("given");
print "Content-type: text/html", "\n\n";
print "<HTML>";
print "<HEAD>";
print "<TITLE>This is what you sent me</TITLE></HEAD>";
print "<body bgcolor=#ffffff>";
print "<h2>This is what you sent me</h2>";

print "Given name: <strong>", $given, "</strong>.<br>", "\n";
print "Family name: <strong>", $family, "</strong>.<p>", "\n";
print "Here's the complete (URL-encoded) data which you submitted:\n";
print "<blockquote>\n<pre>";
print $ENV{QUERY_STRING};
print "</pre>\n</blockquote>\n";

print '<a href="/subjects/bitcne/lectures/l22.d/Lect22.html#form">Back</a>',"\n";
print "to the lecture notes.\n";
print "</BODY>";
print "</HTML>";

exit(0);
The tutorial for this lecture is Tutorial #22.
La Trobe Uni Logo [Previous Lecture] [Lecture Index] [Next Lecture]
Copyright © 2001 by Philip Scott, La Trobe University.
Valid HTML 3.2!

previous | start