#!/usr/local/bin/perl use CGI; $cgi = new CGI(); $sendmail = '/usr/lib/sendmail -t -oem -oi'; $recipient = 'info@chicksonsticks.org'; $redirect = 'confirmation.html'; %fields = ( first_name => 'First Name', middle_initial => 'Middle Initial', last_name => 'Last Name', age => 'Age', occupation => 'Occupation', occupation_other => 'Occupation (other)', street => 'Street', city => 'City', state => 'State', zip => 'Zip', home_area_code => 'Home Phone Area Code', home_prefix => 'Home Phone Prefix', home_number => 'Home Phone Number', work_area_code => 'Work Phone Area Code', work_prefix => 'Work Phone Prefix', work_number => 'Work Phone Number', cell_area_code => 'Cell Phone Area Code', cell_prefix => 'Cell Phone Prefix', cell_number => 'Cell Phone Number', email => 'Email', emergency_name => 'Emergency Contact', emergency_area_code => 'Emergency Contact Area Code', emergency_prefix => 'Emergency Contact Prefix', emergency_number => 'Emergency Contact Number', experience => 'Experience', surfrider_member => 'Surfrider Member', own_board => 'Own Board', board => 'Needs a Board', shirt_size => 'Shirt Size', ); @required = qw( first_name last_name age street city state zip email emergency_name experience surfrider_member own_board shirt_size occupation ); %allowed = ( state => [ qw( AL AK AZ AR CA CO CT DE DC FL GA HI ID IL IN IA KS KY LA ME MD MA MI MN MS MO MT NE NV NH NJ NM NY NC ND OH OK OR PA RI SC SD TN TX UT VT VA WA WV WI WY AS FM GU MH MP PW PR VI AA AE AP ) ], occupation => [ qw(student other) ], experience => [ qw(no beginner intermediate) ], surfrider_member => [ qw(yes no) ], own_board => [ qw(yes no) ], board => [ qw(need borrow) ], shirt_size => [ qw(select kids small medium large xl xxl) ] ); print $cgi->header(); if (!$cgi->param()) { &printForm(); exit(); } # populate global form variables foreach $k (keys %fields) { ${"$k"} = $cgi->param($k); ${"$k"} =~ s/^\s*|\s*$//g; } $erref = &checkParams($cgi); if (keys %{$erref}) { &printForm($erref); exit(); } $name = "$first_name "; if ($middle_initial ne "") { if ($middle_initial !~ /\./) { $middle_initial .= "."; } $name .= "$middle_initial "; } $name .= $last_name; $need_board = "yes"; if ($own_board eq "yes") { $need_board = "no"; } if ($board eq "need") { $need_board = "yes"; } $amount = "50.00"; if ($surfrider_member eq "no") { $amount = "65.00"; if ($occupation ne "student") { $amount = "75.00"; } } open MAIL, "|$sendmail" or die "Could not send mail\n"; print MAIL < To: ChicksOnSticks <$recipient> Cc: $email Subject: Chicks on Sticks Summer Camp 2005 Reservation $name $street $city, $state $zip hm: $home_phone wk: $work_phone cell: $cell_phone Age: $age Occupation: $occupation Surfrider Member: $surfrider_member Emergency Contact: $emergency_name $emergency_phone Surfing Experience: $experience Board needed: $need_board Shirt Size: $shirt_size Camp Fee: $amount EOFMAIL close MAIL; open IN, "confirmation.html" or die "Could not send confirmation"; while () { s/\@\@AMOUNT\@\@/$amount/g; s/\@\@NAME\@\@/$name/g; print; } close IN; sub checkParams($$) { my ($cgi) = @_; my %error = (); my $msg = ""; # check for preset params foreach $v (keys %allowed) { next if (${"$v"} eq ""); if (!grep /${"$v"}/, @{$allowed{$v}}) { $error{$v} = 1; $msg = "
  • Your submission contains choices not provided in our form\n"; } } $error{message} .= $msg; $msg = ""; # check for illegal characters foreach $v (qw(first_name middle_initial last_name occupation_other street city state emergency_name)) { if (${"$v"} =~ /[^a-z.\- 0-9]/i) { $error{$v} = 1; $msg = "
  • One or more of your form entries contain characters not allowed!\n"; } } $error{message} .= $msg; $msg = ""; # check for the required entries if ($shirt_size eq "select") { $shirt_size = ""; } my $missing = 0; foreach $v (@required) { if (!${"$v"}) { $error{$v} = 1; $missing = 1; } } if ($occupation eq "other") { if (!$occupation_other) { $error{occupation} = 1; $missing = 1; } else { $occupation = $occupation_other; } } if ($missing) { $error{message} .= "
  • One or more required fields are missing\n"; } # check phone numbers: # we need at least on of home, work or cell # we need an emergency number # all numbers given must be complete and numerical foreach $type (qw(home work cell emergency)) { foreach $part(qw(area_code prefix number)) { $v = "${type}_${part}"; next unless ${"$v"}; $num{$type} .= ${"$v"}." "; } chop $num{$type}; next if ($num{$type} eq ""); if ($num{$type} !~ /^\d{3} \d{3} \d{4}$/) { $error{"${type}_phone"} = 1; $msg = "
  • Please enter a correct phone number\n"; } $num{$type} =~ s/^(...)/($1)/; ${"${type}_phone"} = $num{$type}; } if (!$emergency_phone) { $error{emergency_phone} = 1; $msg = "
  • Please enter an emergency contact phone number\n$msg" unless ($error{message} =~ /are missing/); } if (!$home_phone && !$work_phone && !$cell_phone) { $error{home_phone} = $error{work_phone} = $error{cell_phone} = 1; $msg = "
  • Please enter either a home, work or cell phone number\n$msg" unless ($error{message} =~ /are missing/); } $error{message} .= $msg; $msg = ""; # check if we had errors $msg = $error{message}; delete $error{message}; if (keys %error) { $error{message} = "We found the following problems or omissions in your submission:\n
      \n$msg\n
    \n"; $error{message} .= "Please correct the indicated fields and resubmit your registration form

    "; if (exists $error{city} || exists $error{state} || exists $error{zip}) { $error{address} = 1; } } return \%error; } sub printForm(;$) { my ($erref) = @_; my %error = %{$erref}; if (!keys %error) { $state = "RI"; } print < Surf Camp 2005 Registration

    Instructional Program Home

    Pictures

    Schedule

    Accommodation

    What to bring

    Directions

    Chicks Home

    Sorry to have missed you!

    Our Summer Camp this year was a great success and we invite you to check back next year or to contact Kira Stillwell, if you are interested in a private session until then!
    EOFHTML }