negzero7 has asked for the wisdom of the Perl Monks concerning the following question:
Hi Perl Monks!
I am working on a project that wants to use an HTML form to read in an order for pizza, and then use a cgi script to output the entered information onto another HTML page.
I have made good progress and my script does what it is suppose to except one thing, it is supposed to be able to read in multiple orders and then output all of them. So far, I can only do one order at a time, and I'm not sure how to make it do multiple orders.
You can view the HTML page and script in action so far if you visit http://nova.umuc.edu/~cm375a20/order_pizza.html . Once you submit my script should do it's magic for oone order.Here is my script, please take a look and see if you can see a way to incorporate multiple orders.
#!/usr/local/bin/perl #Get the submitted data $content_length = $ENV{'CONTENT_LENGTH'}; #Read user data into script variable read (STDIN, $form_data, $content_length); $form_data =~ s/%([\dA-Fa-f][\dA-Fa-f])/pack("C",hex($1))/eg; $form_data =~ s/\+/ /g; @fields = split (/&/, $form_data); #Init script variables with form data values #$form_name is the name of the form. #from the text fields... ($Pizza, $name) = split (/=/, $fields[0]); ($Pizza, $address) = split (/=/, $fields[1]); ($Pizza, $phone) = split (/=/, $fields[2]); ($Pizza, $pizzas) = split (/=/, $fields[3]); ($Pizza, $instructions) = split (/=/, $fields[4]); #from the radio button... ($Pizza, $size) = split (/=/, $fields[5]); #set up variables for the three check boxes. ($cheese, $pepperoni, $sausage) = (0, 0, 0); foreach $type (@fields) { if ($type =~ /cheese/i) { $cheese = 1; } if ($type =~ /pepperoni/i) { $pepperoni = 1; } elsif ($type =~ /sausage/i) { $sausage = 1; } } #Set toppings to be printed out if ($cheese == 1) {@topping[0] = Cheese;} if ($pepperoni == 1) {@topping[1] = Pepperoni;} if ($sausage == 1) {@topping[2] = Sausage;} #Set price if ($size =~ /small/i) {$price = 6.99;} if ($size =~ /medium/i) {$price = 9.99;} elsif ($size =~ /large/i) {$price = 12.99;} #Find Total $total = $price * $pizzas; #Send back to the user a confirmation print << "END_OF_REPLY"; Content-type: text/html <HTML> <HEAD> <TITLE>Confirmation Message</TITLE> </HEAD> <BODY> <p><font size="10">Thanks for Your Order!</font></p> <p><font size="5px" face="Verdana">Please check the following for accuracy.</font></p> Your Name: $name<br> Your Address: $address <br> Your Telephone: $phone <br> <br> Special Instructions: $instructions <br> <br> Here is a summary of your order: <br> # of Pizzas: $pizzas <br> Toppings: @topping <br> Size: $size <br> Price per Pizza: \$$price <br> <hr align="left" width="25%"><br> Total: \$$total </BODY> </HTML> END_OF_REPLY
Also, the only thing for multiple orders is where it prints out the info about the pizza like size, toppings etc.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: CGI script help
by CountZero (Bishop) on May 11, 2008 at 18:49 UTC | |
by Anonymous Monk on May 12, 2008 at 08:21 UTC | |
by CountZero (Bishop) on May 12, 2008 at 17:53 UTC | |
|
Re: CGI script help
by psini (Deacon) on May 11, 2008 at 18:32 UTC | |
|
Re: CGI script help
by pc88mxer (Vicar) on May 12, 2008 at 05:03 UTC | |
|
Re: CGI script help
by toolic (Bishop) on May 13, 2008 at 00:22 UTC | |
|
Re: CGI script help
by leocharre (Priest) on May 12, 2008 at 23:56 UTC | |
|
Re: CGI script help
by Starky (Chaplain) on May 15, 2008 at 14:57 UTC |