#!/usr/bin/perl
# ODBC/Perl Example Two
# Takes input from a textbox, makes sure it is less than five
#   characters, and gives it back to the user.
# Written by : Zack Steinkamp, 9 May 1997

require "cgi-lib.pl";

# Parse arguments
&ReadParse(*in);

# Flush StdOut
$| = 1;

# Print HTTP Header
print &PrintHeader;

#Check to see if the form is filled out
if ($in{'name'}) {
   if (length($in{'name'})>5) {
      $in{'name'} = substr($in{'name'},0,5);
      $message = "ERROR : Can't you READ?  I said FIVE characters!!!";
      &displayForm;
   } else {
      &displayResults;
   }
} else {
   $message = "Example Number Two";
   &displayForm;
}
exit(0);

sub displayResults 
{
print <<END_OF_PRINT
<html>
  <title>Example Two Results</title>
  <body bgcolor="#FFFFFF">
    <font face="Arial" size=4>
      You entered $in{'name'} in the textbox.
    </font><p>
    <font face="Arial" size=3>
      <a href="../examples.html">Back</a> to the examples page.<br>
      <a href="printsource.cgi?file=example2.cgi">View</a> program source.<br>
      <a href="example2.cgi">Execute</a> this program again.
    </font>
  </body>
</html>
END_OF_PRINT
}

sub displayForm
{
print <<END_OF_PRINT
<html>
  <title>Example Number Two</title>
  <body bgcolor="#FFFFFF">
    <p><font size="4" face="Arial">
        <strong>$message</strong>
    </font></p>
    <p><font face="Arial">
       Please enter at most five characters, then click the Submit button...
    </font></p>
    <form action="example2.cgi" method="GET">
      <p><input type="text" size="20" name="name" value="$in{'name'}">
      <input type="submit" name="B1" value="Submit"></p>
    </form>
  </body>
</html>
END_OF_PRINT
}
