August 1998
Intermediate to advanced
800 pages
39h 20m
English
The CGI script in Example 19.9 lets people order t-shirts and sweaters over the Web, using techniques described in Section 19.12. Its output isn’t elegant or beautiful, but illustrating the multiscreen technique in a short program was challenging enough without trying to make it pretty as well.
The shirt and sweater
subroutines check their widget values. If the user somehow submits an
invalid color or size, the value is reset to the first in the list of
allowable colors or sizes.
Example 19-9. chemiserie
#!/usr/bin/perl -w # chemiserie - simple CGI shopping for shirts and sweaters use strict; use CGI qw(:standard); use CGI::Carp qw(fatalsToBrowser); my %States; # state table mapping pages to functions my $Current_Screen; # the current screen # Hash of pages and functions. %States = ( 'Default' => \&front_page, 'Shirt' => \&shirt, 'Sweater' => \&sweater, 'Checkout' => \&checkout, 'Card' => \&credit_card, 'Order' => \&order, 'Cancel' => \&front_page, ); $Current_Screen = param(".State") || "Default"; die "No screen for $Current_Screen" unless $States{$Current_Screen}; # Generate the current page. standard_header(); while (my($screen_name, $function) = each %States) { $function->($screen_name eq $Current_Screen); } standard_footer(); exit; ################################ # header, footer, menu functions ################################ sub standard_header { print header(), start_html(-Title => "Shirts", -BGCOLOR=>"White"); print start_form(); # start_multipart_form() ...Read now
Unlock full access