#!/usr/bin/perl -w #use strict; # conflict with CGI hash use CGI qw/:standard/; use Data::FormValidator::Constraints (qw/valid_email/); use Data::FormValidator::Constraints (qw/valid_american_phone/); $CGI::POST_MAX=1024 * 100; # max 100K posts $CGI::DISABLE_UPLOADS = 1; # no uploads # Location of e-mail program $mailprog = "/usr/sbin/sendmail"; my $toemail; my $fromemail = ""; my $test = 'test'; my $lnameprint; my $fnameprint; my $emailprint; my $phoneprint; my $previewflag = escapeHTML(param('previewflag')); my $formflag = escapeHTML(param('formflag')); my $prevbtn = escapeHTML(param('prevbutton')); my $prevcancel = escapeHTML(param('prevcanbutton')); my $firstname; my $lastname; my $email; my $phone; my $carrier; my $product_title; my $description; my $image_url; my $text_mail; print "Content-type: text/html\n\n"; if ($formflag eq 'sent') { #print $formflag . "is sent.\n"; #skip the form if (param()) { $firstname = escapeHTML(param('firstName')); $lastname = escapeHTML(param('lastName')); $email = escapeHTML(param('email')); $phone = escapeHTML(param('phone')); $carrier = escapeHTML(param('phoneCarriers')); &email_validate; &phone_validate; if (($firstname ne "") && ($lastname ne "") && ($email ne "invalid") && ($phone ne "invalid")) { # print preview page &print_head(); &print_preview_page(); }else{ # set some variables to echo back user selections &error_fname(); &error_lname(); &error_email(); &error_phone(); &print_head(); &print_error_page(); &print_tail(); } # end if }else { #error page &print_error_page(); } # end if (param()) { }elsif ($previewflag eq 'go') { print "Name is $firstname\n"; $firstname = escapeHTML(param('firstName')); print "First name is $firstname\n"; $lastname = escapeHTML(param('lastName')); print "Last name is $lastname\n"; $email = escapeHTML(param('email')); print "Email is $email\n"; $phone = escapeHTML(param('phone')); print "Phone is $phone\n"; $carrier = escapeHTML(param('phoneCarriers')); print "Carrier is $carrier\n"; &email_replace(); &email_to_text(); &mail_form_data(); &number_replace(); &text_form_data(); &print_head(); &print_thank_you_page(); &print_tail(); }else{ &print_head; &print_form; } # =========================================================== subroutines ========================================================================================= # sub number_replace { $phone =~ s/ //; $phone =~ s/\)//; $phone =~ s/ \) //; $phone =~ s/ \)//; $phone =~ s/\) //; } # end sub ================================================================== sub phone_validate { if (valid_american_phone($phone)) { # Phone number is valid print "Phone - Input is valid.\n"; }else{ $phone = 'invalid'; print "Phone - Input is invalid.\n"; } $phone; } # end sub phone_validateb =================================================== sub email_validate { if (valid_email($email)) { # email is valid print "Email - Input is valid.\n"; } else { $email = 'invalid'; print "Email - Input is invalid.\n"; } # end if } # end sub email_validateb =================================================== sub email_replace { $email =~ s/\@/\@/; print "After replacement, email is now $email\n"; } # end sub =================================================================== sub email_to_text { if ($carrier =~ /att/i) { $text_mail = "$phone\@txt.att.net"; }elsif($carrier =~ /cricket/i) { $text_mail = "$phone\@sms.mycricket.com"; }elsif ($carrier =~ /metro/i) { $text_mail = "$phone\@mymetropcs.com"; }elsif ($carrier =~ /sprint/i) { $text_mail = "$phone\@messaging.sprintpcs.com"; }elsif($carrier =~ /tmobile/i) { $text_mail = "$phone\@tmomail.net"; }elsif($carrier =~ /uscellular/i) { $text_mail = "$phone\@email.uscc.net"; }elsif($carrier =~ /verizon/i) { $text_mail = "$phone\@vtext.com"; }elsif($carrier =~ /virgin/i) { $text_mail = "$phone\@vmobl.com"; } # end if print "Carrier email is $text_mail\n"; } # end sub ================================================================== sub mail_form_data { # emails the form data my(@values,$key); # Open the sendmail program and pipe the data open(MAIL, "| $mailprog -t") || die "I can't open $mailprog\n"; print MAIL "To: <$email>\n"; print MAIL "From: \n"; print MAIL "Subject: Price Request\n"; print MAIL "\n"; foreach $key (param) { print MAIL "$key: "; @values = param($key); print MAIL join(", ",@values),"\n"; } print MAIL "\n"; close(MAIL) } # end sub mail_form_data ================================================== sub text_form_data { # emails the form data my(@values,$key); # Open the sendmail program and pipe the data open(MAIL, "| $mailprog -t") || die "I can't open $mailprog\n"; print MAIL "From: \n"; print MAIL "To: <$text_mail>\n"; print MAIL "Subject: Price Request\n"; print MAIL "\n"; foreach $key (param) { print MAIL "$key: "; @values = param($key); print MAIL join(", ",@values),"\n"; } print MAIL "\n"; close(MAIL) } # end sub text_form_data ================================================== sub form_field_values { my(@values,$key); print "

Here are the current settings in this form

"; foreach $key (param) { print "$key -> "; @values = param($key); print join(", ",@values),"
\n"; } } #end sub form_field_values ================================================ sub error_fname { if($firstname eq "") { $fnameprint = '
This Field Is Required --->
'; }else{ $fnameprint = ''; } } # end sub error_fname ===================================================== sub error_lname { if($lastname eq "") { $lnameprint = '
This Field Is Required --->
'; }else{ $lnameprint = ''; } } # end sub error_lname ===================================================== sub error_email { if($email eq "" || "invalid") { $emailprint = '
This Field Is Required --->
'; }else{ $emailprint = ''; } } # end sub error_email ===================================================== sub error_phone { if($phone eq "invalid" || "") { $phoneprint = '
This Field Is Required --->
'; }else{ $phoneprint = ''; } } # end sub error_phone ===================================================== sub print_tail { print <
TAIL } # end sub print_tail ==================================================== sub print_head { print < SkiBee Stores, inc. HEAD } # end sub print_head ==================================================== sub print_thank_you_page { print <
Thank you! Please check your email and/or phone for the price!
THANKYOU_PAGE } # end print_check_page ======================================================== sub print_preview_page { print <
Product Item Details
Product Title :
Product Title
Description :
Product Image:
Item # :
Manufacturer Name:
Manufacturer # :
Free Shipping :
Yes
MSRP Price :
Private Club Price :
After form submission, check computer or phone for message revealing price
Request Email for Price
Request Text for Price
PREVIEW_PAGE } # end print_preview_page ======================================================== sub print_error_page { print<
Request Email for Price
$fnameprint
$lnameprint
$emailprint
Request Text for Price
$phoneprint
Terms & Conditions
*
Other Options
Register Register to see private club price now!
Login Login to see private club price now!
ERROR_PAGE } # end print_error_page ========================================================== sub print_form { #displays the first form #print "Content-type: text/html\n\n"; print <
Request Email for Price
Request Text for Price
Terms & Conditions
*
Other Options
Register Register to see private club price now!
Login Login to see private club price now!
HTML } # end sub print_form =======================================================