#!perl
# Fig. 26.13: form.pl
# Program to read information sent to the server
# from the FORM in the form.html document.

use CGI qw( :standard );

$os = param( "OS" );
$firstName  = param( "FNAME" );
$lastName  = param( "LNAME" );
$email  = param( "EMAIL" );
$phone  = param( "PHONE" );
$book  = param( "BOOK" );

print header;
print "<BODY BACKGROUND = \"images/back.gif\">";
print "<BASEFONT FACE = \"ARIAL,SANS-SERIF\" SIZE = \"3\">";

if ( $phone =~ / ^ \( \d{3} \) \d{3} - \d{4} $ /x )
{
   print <<End_Success;
      Hi <FONT COLOR = "BLUE"><B>$firstName</B></FONT>.
      Thank you for completing the survey.<BR>
      You have been added to the 
      <FONT COLOR = "BLUE"><STRONG>$book</STRONG></FONT>
      mailing list.<BR><BR>
      <STRONG>The following information has been saved 
      in our database:</STRONG><BR>
      <TABLE BORDER = "0" CELLPADDING = "0"
          CELLSPACING = 10>
      <TR><TD BGCOLOR = #FFFFAA>Name </TD>
          <TD BGCOLOR = #FFFFBB>Email</TD>
          <TD BGCOLOR = #FFFFCC>Phone</TD>
          <TD BGCOLOR = #FFFFDD>OS</TD></TR>
      <TR><TD>$firstName $lastName</TD><TD>$email</TD>
          <TD>$phone</TD><TD>$os</TD></TR>
      </TABLE>
      <BR><BR><BR>
      <CENTER><FONT SIZE = "-3">
      This is only a sample form. 
      You have not been added to a mailing list.
      </FONT></CENTER>
End_Success
}
else
{
   print <<End_Failure;
      <FONT COLOR = "RED" SIZE = "+2">
      INVALID PHONE NUMBER</FONT><BR>
      A valid phone number must be in the form
      <STRONG>(555)555-5555</STRONG>
      <FONT COLOR = "BLUE"> Click the Back button, 
      enter a valid phone number and resubmit.<BR><BR>
      Thank You.
End_Failure
}

########################################################################## 
# (C) Copyright 2001 by Deitel & Associates, Inc. and Prentice Hall.     #
# All Rights Reserved.                                                   #
#                                                                        #
# DISCLAIMER: The authors and publisher of this book have used their     #
# best efforts in preparing the book. These efforts include the          #
# development, research, and testing of the theories and programs        #
# to determine their effectiveness. The authors and publisher make       #
# no warranty of any kind, expressed or implied, with regard to these    #
# programs or to the documentation contained in these books. The authors #
# and publisher shall not be liable in any event for incidental or       #
# consequential damages in connection with, or arising out of, the       #
# furnishing, performance, or use of these programs.                     #
##########################################################################

