#!/usr/bin/perl # Setting up my include files use strict; use CGI; use CGI::Carp qw(fatalsToBrowser); use Net::SMTP; undef $/; # Creating objects my $q = ""; $q = new CGI; my $email_body = ""; my @params = $q->param; my %param = {}; my %product_names = ( 'product_a' => 'Product A', 'product_b' => 'Product B'); foreach (@params) { $param{$_} = 1; } $email_body.="calling HANDLE_PERSONAL_INFORMATION\n"; HANDLE_PERSONAL_INFORMATION(); $email_body.="calling HANDLE_PRODUCTS\n"; HANDLE_PRODUCTS(); PRINT_HEADER(); SEND_EMAIL($email_body); #print $email_body; exit; sub HANDLE_PRODUCTS { #this is where I will do all the product handling my @last_params = keys %param; $email_body.="Listing products selected:\n"; foreach (@last_params) { $email_body .= $product_names{$_} . "($_): " . $q->param($_) . "\n" if($q->param($_) != 0); } } sub HANDLE_PERSONAL_INFORMATION { my $order_num = $_[0]; my @personal_information = ('name', 'street', 'city', 'state', 'zip', 'phone', 'email'); my @errors = HANDLE_INFORMATION(@personal_information); if(($errors[0] != 0) || ($#errors > 1)){ # I have created an error please help PRINT_HEADER(); HANDLE_ERRORS(@errors); PRINT_FOOTER(); exit; } } sub HANDLE_INFORMATION { my @columns = @_; $email_body.="Inside HANDLE_INFORMATION with columns: @columns\n"; my @errors = (); foreach (@columns){ my $temp = $q->param("$_"); if($temp ne ''){ delete($param{$_}); $email_body .= uc $_; $email_body .= ": $temp\n"; } else { #debuging push @errors, $_; } } if($#errors == 0){ return 0; } else { return @errors; } } sub HANDLE_ERRORS { ####################################### # This handles all the errors that # # the user causes # ####################################### foreach (@_){ my $temp = ucfirst($_); print "$temp is required
\n"; } print "Please hit the back button and fill out all the fields\n"; } sub PRINT_HEADER { print $q->header; print < PAGE TITLE HEADER GOES HERE EODUMP } sub PRINT_FOOTER { print < EODUMP } sub SEND_EMAIL { my $smtp = Net::SMTP->new("my.email.server") or HANDLE_ERROR("Can not submit. System Down."); $smtp->mail ('email@domain'); $smtp->to ('email@domain'); $smtp->data(); $smtp->datasend("To: email\@domain\n"); $smtp->datasend("From: email\@domain\n"); $smtp->datasend("Subject: Order\n"); $smtp->datasend("\n"); $smtp->datasend($email_body); $smtp->dataend(); $smtp->quit; print "Your order has been submitted.
\n"; print "You should be contacted shortly
\n"; my @array = split(/\n/, $email_body); foreach(@array){ print "$_
"; } }