Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Message to sender after submiting the form

Status
Not open for further replies.

chorta

Technical User
Apr 17, 2007
3
0
0
US
How can i set up this form action to send a custom message to the email entered on the "email" input field once they click submit ?

------------------------------------------------------------

#!/usr/bin/perl
#####################################################################
# 20020308 kmac
# cgi script
#####################################################################
BEGIN { $debug = 0; }

use SybEnv;
use Sybase::CTlib;
use CGI_Input;
ct_callback(CS_CLIENTMSG_CB,\&msg_cb);
ct_callback(CS_SERVERMSG_CB, "srv_cb");

$|=1;
$soedb = "cfwe43alit2";
$soetbl = "es5sgss";
$event_name = "Annual Site Visit";
$event_date = "20070430";
$event_type = "Annual Site Visit";

$destaddr = 'chorta@mydomain.com'; # destination address for email
$err_msg='';
$data_msg='';

chop($date = `date "+%d-%h-%Y"`); # date
chop($time = `date "+%I:%M:%S %p"`); # time
$webmaster = 'webguy@mydomain.com'; # party responsible for form/cgi script
#####################################################################

###########################################################################
# print header
print "Content-type: text/html\n\n";

###########################################################################
# Process incoming data

# decode and split input data
$Vars=CGI_Input::parse_indata(); # $Vars is a ref to hash


##########################################
# Assign values to variable names

while ( ($name,$value) = each(%$Vars) ) {

# sanity check on the length of variable data submitted.
$$name = substr($value,0,255);
# these are the only characers allowed, delete everything else
$$name =~ tr/[a-zA-Z0-9_\-\.@\/' '()]//cd;
# don't allow these special chars
$$name =~ s/'|%|"/ /g;

if ($debug) {print "$name equals $$name<BR>\n";}

}
#########################################
# Check variables passed in

#these are the only variables allowed; reject if they send anything else.
@allowed_vars = qw(address city comments company email fname institution lname other_notified participation_reason position topics_area_interest attend_workshop submit);

$bad_var = CGI_Input::allowed_vars(\@allowed_vars, $Vars);

if ($bad_var) {
$err_msg = "Rejected Submission -- Bad Variable Passed: $bad_var
<P>Please hit the Back button on your browser and try again.";
error_form("Bad Variable");
} elsif ($debug) {
print "All vars OK<BR>\n";
}


#########################################
# Check for required variables

@required_vars = qw(fname lname position institution address email);

($missing_vals) = CGI_Input::required_vars(\@required_vars,0); # ref to array

if ($missing_vals) {
#print "Missing Vals: @$missing_vals<BR>\n";

for ($i=0;$i<@$missing_vals;++$i) {
$missing_vals_html .= "<BR>" . uc(@$missing_vals[$i]);
}

$err_msg = "You must fill in the following field(s):<BR><B> $missing_vals_html</B>
<P>Please hit the Back button on your browser and try again.";
error_form("Missing Values");
} elsif ($debug) {
print "OK - No Missing Vals<BR>\n";
}

#########################################
# check for valid email and phone format
check_valid_format();

registration_data();
# convert to upper case to display
$attend_dinner = uc $attend_dinner;
$attend_event = uc $attend_event;

# send email to administrator
send_email();

# Everything is OK. Display message that form was sent.
ok_form();

#########################################
# SUBROUTINES #
#########################################

#############################################################
# Send email with form values.

sub send_email {
if (open (MAIL, "|/usr/lib/sendmail -t -oi" ))
{
print MAIL "To: $destaddr $email\n";
print MAIL "Subject: TDLC SLC Annual Site Visit";
print MAIL "\nThis is your confirmation for the TDLC SLC Annual Site Visit\n\n";
print MAIL "Date: $date; Time: $time\n";
print MAIL "******************************************************\n";
print MAIL "Name: $lname, $fname\n\n";
print MAIL "Title/Position: $position\n\n";
print MAIL "Institution/Company: $institution\n\n";
print MAIL "Address: $address\n\n";
print MAIL "Email: $email\n\n";
print MAIL "TDLC Affiliation: $attend_workshop\n\n";
print MAIL "Network Affiliation: $company\n\n";
print MAIL "Associated Facilities: $topics_area_interest\n\n";
print MAIL "TDLC Projects: $other_notified\n\n";
print MAIL "Role on project: $city\n\n";
print MAIL "NSF Bio Sketch: $comments\n\n";
print MAIL "Comments: $participation_reason\n\n";
print MAIL "******************************************************\n";
print MAIL "Thank you for registering.\n";
close MAIL;
} else {
$err_msg = " The form you filled out could not be mailed.<BR>
Please contact <A HREF=\"mailto:$webmaster\">$webmaster</A> ";
error_form("Mail Error");
}
}

#################################################################
sub check_valid_format {

if ($email !~/.*@.*\./i){
$err_msg= "\nInvalid email address<BR>
<I>$email</I>
<P>Please hit the Back button on your browser and try again.";
error_form("Invalid Email");
}

}

##################################################################
sub registration_data {
# put poster info in sybase table
$num_rows=0;
#call the sybase connect subroutines
$dbh=SybEnv::sybase_connect();
$sql = "insert $soedb..$soetbl (event_name, event_date, lname, fname, position, email, institution, comments, input_date, event_type, city, address, other_notified, participation_reason, topics_area_interest, company, attend_workshop)
values ('$event_name', '$event_date', '$lname', '$fname', '$position', '$email', '$institution', '$comments' ,getdate(), '$event_type', '$city', '$address','$other_notified','$participation_reason','$topics_area_interest', '$company', '$attend_workshop')";
if ($debug) {print "<BR> sql: $sql<BR>\n";}
$dbh->ct_sql("$sql");
$num_rows = $dbh->{ROW_COUNT};
if ($num_rows ne "1") {
$err_msg = "There was an error processing your submission<BR>
Please contact <A HREF=\"mailto:$webmaster\">$webmaster</A>
to report this";
error_form("Database Error");
} else {
$data_msg = "Personal info successfully entered.";
}
}

#################################################################
sub ok_form {

print <<EOM;
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Success</title>
<meta http-equiv="REFRESH" content="0;url=complete.html"></HEAD>
<BODY>
</BODY>
</HTML>

EOM

}

#############################################
sub error_form {

my $title=$_[0];

if (!$title) {$title="Submission Error";}


print "<HTML><HEAD><TITLE>$title</TITLE>
<STYLE TYPE=text/css>
<!--
TH {font-size: 13pt; font-color:#7E9C4F; font-family: Arial,Helvetica,san-serif;}
TD {font-size: 10pt; font-color:#333333; font-family: verdana,Helvetica,san-serif;}
-->
</STYLE>
</HEAD>
<BODY BGCOLOR=#1E3361>
<CENTER>
<TABLE BGCOLOR=#FFFFFF CELLSPACING=9 CELLPADDING=5 BORDER=0>
<TR><TH>
Error Submitting Information!<BR>
<FONT COLOR=#CC0000>$title</FONT>
</TH></TR>
<TR>
<TD BGCOLOR=#FFFFFF>Date: $date<BR>
Time: $time<BR><BR>
$err_msg
</TD>
</TR>
</TABLE>
</BODY></HTML>";

exit(1);

}
###############################################
sub msg_cb {
my($layer, $origin, $severity, $number, $msg, $osmsg) = @_;
if ($severity > 10) {
printf STDERR "\nOpen Client Message: (In msg_cb)\n";
printf STDERR "Message number: LAYER = (%ld) ORIGIN = (%ld) ",
$layer, $origin;
printf STDERR "SEVERITY = (%ld) NUMBER = (%ld)\n",
$severity, $number;
printf STDERR "Message String: %s\n", $msg;
if (defined($osmsg)) {
printf STDERR "Operating System Error: %s\n", $osmsg;
}
printf STDERR "\nExiting on Open Client error\n";
$err_msg = "\n<P>Exiting on Open Client error<BR>\n$msg\n<BR>
<P><B>Sorry, your registration was not processed.<P></B>
Please report this error message to
<A HREF=\"mailto:$webmaster\">$webmaster</A>";
error_form("Open Client Error");
} else {
CS_SUCCEED;
}
}

sub srv_cb {
my($cmd, $number, $severity, $state, $line, $server, $proc, $msg) = @_;
if ($severity > 10) {
printf STDERR "\nServer message: (In srv_cb)\n";
printf STDERR "Message number: %ld, Severity %ld, ",
$number, $severity;
printf STDERR "State %ld, Line %ld\n", $state, $line;
if (defined($server)) {
printf STDERR "Server '%s'\n", $server;
}
if (defined($proc)) {
printf STDERR " Procedure '%s'\n", $proc;
}
printf STDERR "Message String: %s\n", $msg;
printf STDERR "\nExiting on Server error\n";
$err_msg = "\n<P>Exiting on Server error:\n<BR>$msg\n<BR>
<P><B>Sorry, your registration was not processed.<P></B>
Please report this error message to
<A HREF=\"mailto:$webmaster\">$webmaster</A>";
error_form("Server Error");
} else {
CS_SUCCEED;
}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top