The University of Texas at Austin- What Starts Here Changes the World
Services Navigation


Customized Response

This script processes a Web form and displays a customized response to the browser.

Open the text editor to write the script:

pico custom

Type the following Perl code in your text editor exactly as it appears here:

#!/usr/local/bin/perl
use CGI;
CGI::ReadParse(*in);
print "Content-type:text/html\n\n";
print '<HTML><HEAD><TITLE>custom results</TITLE></HEAD>';
print '<BODY BGCOLOR="FF0066">';
print '<h2>Thank You!</h2>';
print "<p>Thank you, $in{name}, for filling out our form.";
print "Here is a $in{color} cloak to help you in your quest,";
print "$in{quest}</p>";
print '</BODY></HTML>';

Save the file and exit the editor.

Make the script executable, type:

chmod 755 $HOME/public_html/cgi-bin/custom
This table includes a line-by-line explanation of the "custom" CGI script:
#!/usr/local/bin/perl Tells the server the Perl interpreter is located in the directory /usr/local/bin/perl
use CGI;
Loads the CGI module
CGI::ReadParse(*in);
A method from the CGI module that takes the form field information and saves it as the hash %in. The formfield names are the keys of the hash.
print "Content-type:text/html\n\n";
Is a print statement for the HTTP header. In this case, the header tells the Web browser to display HTML formatted text.
print '<HTML><HEAD><TITLE>custom results</TITLE></HEAD>';
print '<BODY BGCOLOR="FF0066">';
These print statements start the HTML document, create the <HEAD> section, and begin the <BODY> section of the HTML page.
print "<p>Thank you, $in{name}, for filling out our form.";
print "Here is a $in{color} cloak to help you in your quest,";
print "$in{quest}</p>";
These print statements use single elements of the %in hash to create a customized response to the Web form.
print '</BODY></HTML>'; This print statement closes the HTML document.

 

 

 


  Updated 2006 August 14
  Comments to TeamWeb