Exercise 9

By f22raymond

1.      Code of the form is:

<form ACTION=”process.pl” METHOD=POST>

<table>

           <tr>

                     <td>Name:</td>

                     <td>

                     <input type=”text” name=”name” value=”Evan Burke”>

                     </td>

           </tr>

<br>

<br>

           <tr>

                     <td>Credit Card:</td>     

               <td>

                     <input type=”radio” name=”card” value=”Visa” checked> Visa

                     <input type=”radio” name=”card” value=”Master”>Master

                     </td>

           </tr>

<br>

<br>

           <tr>

           <td>Card Number:</td>

           <td>

           <input type=”text” name=”number” value=”8443261344895544″>

           </td>

           </tr>

<br>

<br>

           <tr>

                     <td>Order:</td>

                     <td>

                     <input type=”text” name=”order” value=”French perfume”>                   

                     </td>

           </tr>

<br>

<br>

</table>

<input type=”submit” value=”Submit”>

</form>

 

        Screen of the form is:

       

 

2.      Searched from Internet, the typical perl script for processing html form involved the following steps:

                            i.               Use CGI modules to read data passed from a form.

          e.g.         use CGI qw (:cgi-lib :standard);

                          ii.                Use function to grab the data passed from the form

                                   and puts it into an array.

          e.g.  &ReadParse(%in);

                        iii.                Get the value from the form and assign to variable.

          e.g.  $name = $in{“name”};

                        iv.                Print HTML document

           e.g.  print<<EOSTUFF;

 

3.      The script was modified as below to process the form above.

  #!/usr/bin/perl

 

  # Program Name: process.pl

  # Author: Kwok Keung NG

  # This program uses the data passed by the form program and creates

  # a new web page with that information. 

 

  use CGI qw(:cgi-lib :standard);  # Use CGI modules that let people read data passed from a form

 

 

  &ReadParse(%in);                 # This grabs the data passed by the form and puts it in an array

 

  $name = $in{“name”};             # Get the user’s name and assign to variable

  $card = $in{“card”};               # Get the credit card type and assign to variable

  $cnumber = $in{“number”};        # Get the credit card’s number and assign to variable

  $order = $in{“order”};             # Get the order information and assign to variable

 

  print<<EOSTUFF;                             # Start printing HTML document

Leave a Reply