#!/usr/bin/perl -wT ###################################################################################### # Email Newsletter Form for CnK # By Tim Reynolds # 11/28/2001 ###################################################################################### #### # To Do: # # IMPORTANT!!!!!!!!!!! # - Add hidden fields to every section with a for loop in order to save state for the data # use the for loop in the confirm routine of the html code as an example. #### ######################################## # Configuration Area # ####################################### #### # CGI.pm config #### use CGI qw (:standard); use CGI::Carp qw(fatalsToBrowser); $q = new CGI; # set path for links in lib file $pathL2 = '/L2'; #### #### # Field Configuration #### ## This array is the names of the fields that you want in your database. @fields = ( "your_email", "companion_email", 'hear' ); $field_count = @fields; ## This array holds the name of each field (Rendered HTML) that appears next to the field @field_names = ("Email", "Email", "How did you hear about Cox & Kings?"); #### # Import all variables #### import_names('IN'); #### # Field Values # # these are the values that are processed after the user inputs information #### @fields_vals = ($IN::your_email, $IN::companion_email, $IN::hear); #### end of field configuration #### # HTML Library File # # html for form which includes user input -- confirmation pages and initial page #### # live require "/u/web/coxan2/cgi-local/email_news/email_news_html_bl.lib"; require "/u/web/coxan2/cgi-local/subr/fullPage.lib"; #require "/Library/WebServer/CGI-Executables/email_news/email_news_html_bl.lib"; #require "/Library/WebServer/CGI-Executables/subr/fullPage.lib"; ### # Sendmail Config # # location of sendmail #### # set path for sendmail # needed in order to run with -T $ENV{PATH} = "/bin:/usr/lib"; # live path $mail_loc = "/usr/lib/sendmail -t"; # #### local setting - make to change back to live setting #### # # #$mail_loc = "/usr/sbin/sendmail -t"; ##### # Variable Configuration ##### # main variable config $to = "tours\@coxandkingsusa.com"; #$to = "tim\@cdmusicpage.com, susan\@mcreative.com"; $from = "tours\@coxandkingsusa.com"; $subject = "Email Newsletter Form"; # used in travel_form_html.lib to set form action url $script = "http://www.coxandkingsusa.com/cgi-local/email_news/email_news.cgi"; #$script = "http://192.168.1.101/cgi-local/email_news/email_news.cgi"; # sets font size and face for all form fields $font = ""; # sets font size and face for all main text that appears above the form $main_text_font = ""; # variable for actions $action = $q->param("action"); # required parameters @REQUIRED = qw/your_email/; ### end of variable config #### # Date and Time config #### use POSIX 'strftime'; my $date = strftime('%D', localtime); my $str_time = strftime('%T', localtime); #### #### # DO I NEED TO print this header? # already have this in subroutine html code? #### print $q->header; ####################################################################### # end of config area # ####################################################################### #### # Actions #### if($action =~ /submit/i){ # Add the record passed from the add record page &top_html; &check_print; &response_form; &bottom_html; } elsif($action =~ /confirm/i){ # Add record and display final page ✓ } else { &top_html; &first_form; &bottom_html; } exit; #### end of actions #### # Subroutines #### #### # Check # # checks to see if any parameters are missing # then fills @_ or doesn't and then this is checked # in the confirm action #### sub check { my @missing = check_missing(param()); # this may also work !$scalar(@array) # if no data exists in @missing # then all data should be valid # so mail it out! if (@missing == 0) { &mail; &top_html; &confirm_form; &bottom_html; } else { &top_html; &check_print; &response_form; &bottom_html; } } #### end of check #### # Check Print #### sub check_print { my @missing = check_missing(param()); if (@missing) { print "
"; print_warning(@missing); print "
"; return undef; } } #### end of check print sub check_missing { my (%p); grep (param($_) ne '' && $p{$_}++,@_); return grep(!$p{$_},@REQUIRED); } #### end of check missing #### # Mail #### sub mail { # Mail Label label is the file handle # the location of the send mail library open (MAIL, "| $mail_loc"); print MAIL "To: $to\n"; print MAIL "Bcc: rodgers\@mcreative.com, tmrworks\@pacbell.net\n"; print MAIL "From: $from\n"; print MAIL "Subject: $subject \n\n"; print MAIL "Email Newsletter Signup: \n"; print MAIL "------------------------------------\n"; print MAIL "User's Email: $fields_vals[0]\n"; # new how did you hear print MAIL "\n"; print MAIL "How did you hear about Cox & Kings?: $fields_vals[2]"; print MAIL "\n"; print MAIL "\n"; if ($IN::companion_email) { print MAIL "Companion Email: $fields_vals[1] \n"; print MAIL "\n"; print MAIL "\n"; print MAIL "------------------------------------\n"; } else { print MAIL "\n"; print MAIL "------------------------------------\n"; } close (MAIL); } #### # Print Warning #### sub print_warning { # removes underscores from parameter names foreach $item (@_) { $item =~ s|_| |gs; } print font({-color=>'red'}, 'You must enter information into the following field(s): ', ); print font({-color=>'black'}, em(join(', ',@_)), ); } #### end of print warning #### # Validation Check #### sub valid{ #import_names('IN'); #if ($IN::name eq "" || $IN::email eq "") {print "no name\n";} }