1 #! /usr/npac/bin/perl -w 2 3 ############################################################################# 4 # 5 # File: fill-out-form.pl 6 # 7 # Output: CGI.pm version of pizza order form 8 # 9 # Description: Creates a pizza order from the information obtained from 10 # a pizza order form. Both the order form and the order 11 # are created by this script (i.e., all HTML is generated 12 # on-the-fly) 13 # 14 # 15 ############################################################################# 16 # 17 # Initialization 18 # 19 ############################################################################# 20 21 $HOSTPATH = 'http://osprey7.npac.syr.edu:3768/users-cgi/trscavo/tutorials/CGI/examples/more-cgi'; 22 23 ############################################################################# 24 # 25 # Modules 26 # 27 ############################################################################# 28 29 # Import a standard set of methods and the HTML shortcuts 30 # from CGI.pm (see page 187 of the Llama book for details): 31 use CGI qw(:standard :shortcuts); 32 33 ############################################################################# 34 # 35 # Main Routine 36 # 37 ############################################################################# 38 39 if ( param() ) { 40 ReadInput() && PrintOrder(); 41 } else { 42 PrintForm(); 43 } 44 45 ############################################################################## 46 # 47 # Input 48 # 49 ############################################################################## 50 51 sub ReadInput { 52 $ADDRESS = param('address'); 53 $PHONE = param('phone'); 54 $TOPPING = param('topping'); 55 return 1; 56 } 57 58 ############################################################################# 59 # 60 # Output 61 # 62 ############################################################################# 63 64 sub PrintForm { 65 66 # Print MIME header: 67 print header(-type=>'text/html'); 68 69 # Print first few lines of the HTML document: 70 print start_html( 71 -title=>'CGI Example: Fill-out Form', 72 -BGCOLOR=>'white' 73 ), "\n"; 74 75 # Print a heading: 76 print h2('Internet Pizza Delivery Service'), "\n"; 77 78 # Print <FORM> tag (the arguments below are the defaults 79 # and given only for clarity): 80 print start_form( 81 -method=>'POST', 82 -action=>"$HOSTPATH/fill-out-form.pl" 83 ), "\n"; 84 85 # Print a textfield for the user's street address: 86 print p( "Type in your street address:\n", 87 textfield( 88 -name=>'address', 89 -size=>36 90 ) 91 ), "\n"; 92 93 # Print a textfield for the user's phone number: 94 print p( "Type in your phone number:\n", 95 textfield( 96 -name=>'phone', 97 -size=>20 98 ) 99 ), "\n"; 100 101 # Prompt for pizza: 102 print p( 'What kind of pizza would you like? Check one:' ), "\n"; 103 104 # This form of blockquote requires the CGI shortcuts: 105 print blockquote( 106 radio_group( 107 -name=>'topping', 108 -values=>['Pepperoni','Sausage','Anchovy'], 109 -linebreak=>'true' 110 ) 111 ), "\n"; 112 113 # Print submit and reset buttons: 114 print p( 'To place your order, click here:', 115 submit('Order Pizza'), 116 reset('Clear') 117 ), "\n"; 118 119 # Print </FORM>: 120 print end_form(), "\n"; 121 122 # Print last few lines of HTML document: 123 print end_html(), "\n"; 124 125 } 126 127 sub PrintOrder { 128 129 # Print MIME header: 130 print header(-type=>'text/html'); 131 132 # Print first few lines of the HTML document: 133 print start_html( 134 -title=>'CGI Example: Pizza', 135 -BGCOLOR=>'#ffffff' 136 ), "\n"; 137 138 # Print some headings: 139 print h1( 'Pizza Order' ), "\n"; 140 print h3( "$TOPPING pizza" ), "\n"; 141 142 # Print some paragraphs: 143 print p( "Deliver to: <B>$ADDRESS</B>" ), "\n"; 144 print p( "Telephone: <B>$PHONE</B>" ), "\n"; 145 my $date = `date`; chomp($date); 146 print p( "Order came in at $date" ), "\n"; 147 148 # Print a horizontal rule: 149 print hr(); 150 151 # Print a link: 152 print 'Return to '; 153 print a({href=>"$HOSTPATH/fill-out-form.pl"}, 154 'HTML form' 155 ), "\n"; 156 157 # Print last few lines of HTML document: 158 print end_html(), "\n"; 159 160 }