still learning
07-07-2006, 07:01 PM
I have no knowledge with this perticular language. What im trying to do is, I have an online contact form that works great, except people can leave it blank and click submit. I want to make it where if someone leaves it blank a message like "Please fill out all required fields" will pop up.
also If possible I would like an email message to be sent to the user who fills out the form saying something like "We received your contact form, thanks" or whatever.. any help would be greatly appriciated. THANKS!!!
below is the code I have so far......................................
#!/usr/bin/perl -wT
#
# mail-form cgi
# Quick and dirty Web form processing script. Emails the data
# to the recipient.
#
# You should change any variable that has "CONFIGURE" in the
# comment.
#### modules (these don't need changing)
#
# be strict, define all variables
use strict;
# use CGI.pm for parsing form data and printing headers/footers
use CGI;
# redirect errors to the browser window
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
# create an instance of CGI.pm:
my($cgi) = CGI->new;
# CONFIGURE: change this to the proper location of sendmail on your system:
my($mailprog) = '/usr/sbin/sendmail';
# Set the path, so taint mode won't complain. This should be the path
# that sendmail lives in! (If you're using /usr/lib/sendmail, then
# the path had better be /usr/lib here.)
$ENV{PATH} = "/usr/sbin";
# CONFIGURE: change this to the e-mail address you want to receive the
# mailed form data
my($recipient) = 'james@nospam.com';
my($cc) = 'james@nospam.com';
my($serveremail) = 'server@nospam.com';
# CONFIGURE: change this to your URL:
my($homepage) = "http://www.voicefactor.com/contactthank.htm";
# CONFIGURE: change this to the subject you want the e-mail to have
# WARNING: Do NOT Let the form specify the subject line, or your
# program can be hijacked by spammers!!!
my($subj) = "Online Contact Form Received";
# everything below this shouldn't need changing, except possibly the
# "thank you" page at the end.
# Print out a content-type header
print $cgi->header;
# CGI.pm automatically parses the data, and you can retrieve it using
# $cgi->param("fieldname")
my($sender) = $cgi->param("email");
my($csender) = $cgi->param("cemail");
if ($sender ne $csender) {
print "<html><head><title>Error!</title></head><body>\n<b><h3>Error: Email and Confirmation Email are not the same!</h3></b></body></html>\n\n";
exit;
}
# Now send mail to $recipient
open (MAIL, "|$mailprog -t") || &dienice("Can't open $mailprog!\n");
print MAIL "To: $recipient\n";
print MAIL "Cc: $cc\n";
print MAIL "From: $serveremail\n";
print MAIL "Subject: $subj\n\n";
# print all of the form fields:
foreach my $i ($cgi->param()) {
print MAIL $i . ": " . $cgi->param($i) . "\n";
}
print MAIL "\n\n";
# print some extra info:
print MAIL "Server protocol: $ENV{'SERVER_PROTOCOL'}\n";
print MAIL "HTTP From: $ENV{'HTTP_FROM'}\n";
print MAIL "Remote host: $ENV{'REMOTE_HOST'}\n";
print MAIL "Remote IP address: $ENV{'REMOTE_ADDR'}\n";
close (MAIL);
# Now send mail to $recipient
open (MAIL2, "|$mailprog -t") || &dienice("Can't open $mailprog!\n");
print MAIL2 "To: $sender\n";
print MAIL2 "From: $serveremail\n";
print MAIL2 "Subject: Online Contact Form Received\n\n";
print MAIL2 "\n";
print MAIL2 "We have received your online contact form and we will get back\n";
print MAIL2 "to you as soon as possible.\n";
print MAIL2 "\n\n";
print MAIL2 "VoiceFactor\n";
print MAIL2 "Customer Service Department\n";
close (MAIL2);
# CGI.pm prints the HTML header
print $cgi->start_html(-title=>"Thank You",
-bgcolor=>"#ffffff",
-text=>"#000000");
# CONFIGURE:
# Print a thank-you page - you can customize this however you wish.
# Be sure to use proper HTML, and escape any $-signs or @-signs with a
# backslash, e.g.: \$25.00, nullbox\@cgi101.com
print <<EndHTML;
<meta http-equiv="refresh" content="0;url=$homepage">
EndHTML
# CGI.pm prints the HTML footer
print $cgi->end_html;
# error handler
sub dienice {
my($msg) = @_;
print $cgi->start_html(-title=>"Error");
print qq(<h2>Error</h2>\n);
print $msg;
print $cgi->end_html;
exit;
}
# the end.
also If possible I would like an email message to be sent to the user who fills out the form saying something like "We received your contact form, thanks" or whatever.. any help would be greatly appriciated. THANKS!!!
below is the code I have so far......................................
#!/usr/bin/perl -wT
#
# mail-form cgi
# Quick and dirty Web form processing script. Emails the data
# to the recipient.
#
# You should change any variable that has "CONFIGURE" in the
# comment.
#### modules (these don't need changing)
#
# be strict, define all variables
use strict;
# use CGI.pm for parsing form data and printing headers/footers
use CGI;
# redirect errors to the browser window
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
# create an instance of CGI.pm:
my($cgi) = CGI->new;
# CONFIGURE: change this to the proper location of sendmail on your system:
my($mailprog) = '/usr/sbin/sendmail';
# Set the path, so taint mode won't complain. This should be the path
# that sendmail lives in! (If you're using /usr/lib/sendmail, then
# the path had better be /usr/lib here.)
$ENV{PATH} = "/usr/sbin";
# CONFIGURE: change this to the e-mail address you want to receive the
# mailed form data
my($recipient) = 'james@nospam.com';
my($cc) = 'james@nospam.com';
my($serveremail) = 'server@nospam.com';
# CONFIGURE: change this to your URL:
my($homepage) = "http://www.voicefactor.com/contactthank.htm";
# CONFIGURE: change this to the subject you want the e-mail to have
# WARNING: Do NOT Let the form specify the subject line, or your
# program can be hijacked by spammers!!!
my($subj) = "Online Contact Form Received";
# everything below this shouldn't need changing, except possibly the
# "thank you" page at the end.
# Print out a content-type header
print $cgi->header;
# CGI.pm automatically parses the data, and you can retrieve it using
# $cgi->param("fieldname")
my($sender) = $cgi->param("email");
my($csender) = $cgi->param("cemail");
if ($sender ne $csender) {
print "<html><head><title>Error!</title></head><body>\n<b><h3>Error: Email and Confirmation Email are not the same!</h3></b></body></html>\n\n";
exit;
}
# Now send mail to $recipient
open (MAIL, "|$mailprog -t") || &dienice("Can't open $mailprog!\n");
print MAIL "To: $recipient\n";
print MAIL "Cc: $cc\n";
print MAIL "From: $serveremail\n";
print MAIL "Subject: $subj\n\n";
# print all of the form fields:
foreach my $i ($cgi->param()) {
print MAIL $i . ": " . $cgi->param($i) . "\n";
}
print MAIL "\n\n";
# print some extra info:
print MAIL "Server protocol: $ENV{'SERVER_PROTOCOL'}\n";
print MAIL "HTTP From: $ENV{'HTTP_FROM'}\n";
print MAIL "Remote host: $ENV{'REMOTE_HOST'}\n";
print MAIL "Remote IP address: $ENV{'REMOTE_ADDR'}\n";
close (MAIL);
# Now send mail to $recipient
open (MAIL2, "|$mailprog -t") || &dienice("Can't open $mailprog!\n");
print MAIL2 "To: $sender\n";
print MAIL2 "From: $serveremail\n";
print MAIL2 "Subject: Online Contact Form Received\n\n";
print MAIL2 "\n";
print MAIL2 "We have received your online contact form and we will get back\n";
print MAIL2 "to you as soon as possible.\n";
print MAIL2 "\n\n";
print MAIL2 "VoiceFactor\n";
print MAIL2 "Customer Service Department\n";
close (MAIL2);
# CGI.pm prints the HTML header
print $cgi->start_html(-title=>"Thank You",
-bgcolor=>"#ffffff",
-text=>"#000000");
# CONFIGURE:
# Print a thank-you page - you can customize this however you wish.
# Be sure to use proper HTML, and escape any $-signs or @-signs with a
# backslash, e.g.: \$25.00, nullbox\@cgi101.com
print <<EndHTML;
<meta http-equiv="refresh" content="0;url=$homepage">
EndHTML
# CGI.pm prints the HTML footer
print $cgi->end_html;
# error handler
sub dienice {
my($msg) = @_;
print $cgi->start_html(-title=>"Error");
print qq(<h2>Error</h2>\n);
print $msg;
print $cgi->end_html;
exit;
}
# the end.