Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

Coding Forum


You are currently viewing our Coding Forum as a guest. Please register to participate.
Login



Reply
Checkboxes in CGI formmails query
Old 10-05-2004, 02:58 PM Checkboxes in CGI formmails query
Average Talker

Posts: 15
Trades: 0
Okay, so I've got a script that works fine for sending the contents of a text box in a contact form, but I've played about with commands for checkboxes, and can't get the results to display. What I'm looking for is for the email to say 'Submitter ticked :' and a list of the checkboxes outputting 'true'. Here is the full working code :

Code:
#!/usr/bin/perl

##!/usr/bin/perl
#    chfeedback.pl Feedback Form Perl Script Ver 2.01
#    Generated by thesitewizard.com's Feedback Form Wizard.
#    Copyright 2000-2004 by Christopher Heng. All rights reserved.
#
#				http://www.aberdeendesign.co.uk
#


# ---------- USER CONFIGURATION SECTION ---------------
# Before this script will do anything useful, the following
# variables must be set.
#
# MANDATORY VARIABLES
# $mailprog - the location of your mail program and the parameters
#           to pass to it.
#			eg $mailprog = "/usr/lib/sendmail" ;
# $mailto - email address where the feedback will be sent
#           eg, $mailto = 'yourname@example.com' ;
# $subject - the subject line in the email sent by the feedback form
#           eg $subject = "Feedback Form" ;
#
# $formurl - the URL of your feedback form
#           eg $formurl = "http://www.example.com/feedback.html" ;
# $thankyouurl - the URL of your thank you page
#           eg $thankyouurl = "http://www.example.com/thanks.html" ;
# $errorurl - the URL of your error page
#           eg $errorurl = "http://www.example.com/error.html" ;


$mailprog = "/usr/lib/sendmail" ;
$mailto = 'info@aberdeendesign.co.uk' ;
$subject = "Contact Form" ;
$formurl = "http://www.aberdeendesign.co.uk/html/contact_form.html" ;
$errorurl = "http://www.aberdeendesign.co.uk/html/contact_error.html" ;
$thankyouurl = "http://www.aberdeendesign.co.uk/html/thank_you.html" ;


# ---------- END OF USER CONFIGURATION SECTION ------------

# ---------- functions -----------
sub redirect_url {
	my ( $url )	= shift ;
	print "Location: $url\n\n" ;
}

sub parse_form_data {
	my ($request_method, $input_string, $content_length) ;
	my (@vars, $indiv_var, $name, $value);
	my (%form) ;

	$request_method	= $ENV{'REQUEST_METHOD'} ;
	$content_length	= $ENV{'CONTENT_LENGTH'} ;

	# load the entire string into $input_string
	if ($request_method	=~ /post/i) {
		$input_string	= "" ;
		read( STDIN, $input_string, $content_length ) ;
	}
	else {
		$input_string	= $ENV{ 'QUERY_STRING' };
	}
	unless (defined $input_string) {
		$input_string	= "" ;
	}

	# put all the variable pairs (name=value) into an array
	@vars	= split( /&/, $input_string );

	# process each individual name, value pair, putting them
	# into a hash for easy access
	foreach $indiv_var ( @vars ) {

		# separate the pair
		($name, $value)	= split( /=/, $indiv_var, 2 );

		# translate encoding
		$name	=~ s/%([\da-fA-F]{2})/pack("C", hex($1))/eg;
		$name	=~ tr/+/ /;
		unless (defined $value) {
			# just in case there was no equals as in ISINDEX
			$value	= "" ;
		}
		$value	=~ s/%([\da-fA-F]{2})/pack("C", hex($1))/eg;
		$value	=~ tr/+/ /;

		# put the pair in the hash for easy access
		$form{$name}	= $value ;
	}

	return wantarray ? %form : undef ;
}

sub send_email {
	my ($mailprog, $email, $name, $mailto, $subject, $message) = @_ ;

	if (open MAIL, "|$mailprog -t") {
		print MAIL "To: $mailto\n" ;
		print MAIL "From: \"$name\" <$email>\n" ;
		print MAIL "Reply-To: \"$name\" <$email>\n" ;
		print MAIL "X-Mailer: chfeedback.pl 2.01\n" ;
		print MAIL "Subject: $subject\n\n" ;
		print MAIL $message ;
		close MAIL ;
	}
	# ignore fails, just don't do anything

	return ;
}

# ----------- main program ------

my %form = parse_form_data();

my $email ;
if (exists $form{"email"}) {
	$email	= $form{"email"} ;
}
else {
	redirect_url( $formurl );
	exit ;
}
if ($email eq "") {
	redirect_url( $errorurl );
	exit ;
}

my $name = $form{"name"} ;
if ($name eq "") {
	redirect_url( $errorurl );
	exit ;
}

my $comments = $form{'comments'} ;
if ($comments eq "*****") {
	redirect_url( $errorurl );
	exit ;
}

my $phone = $form{'phone'} ;
if ($phone eq "") {
	redirect_url( $errorurl );
	exit ;
}

my $businessname = $form{'businessname'} ;
if ($businessname eq "*****") {
	redirect_url( $errorurl );
	exit ;
}

my $http_referer = $ENV{ 'HTTP_REFERER' };
my $message	=
	"This message was sent from:\n" .
	"$http_referer\n\n" .
	"------------------------------------------- Details --------\n\n" .
	"Name:\n" .
	"$name\n\n" .
	"Email:\n" .
	"$email\n\n" .
	"Business Name:\n" .
	"$businessname\n\n" .
	"Telephone No:\n" .
	"$phone\n\n" .
	"Additional Comments:\n" .
	$comments . 
	"\n\n------------------------------------------------------------\n" ;
	
send_email ( $mailprog, $email, $name, $mailto, $subject, $message );
redirect_url( $thankyouurl );
I'm sure there's something obvious I'm missing, but I can't seem to work it out. For reference, The 8 checkboxes in question on http://www.aberdeendesign.co.uk/html/contact_form.html are named by number and valued according to the text next to them [eg - the first checkbox' Object ID and Name is '1' and its Value is 'Web Design'].

Any help would be greatly appreciated, as I'm sure this seems like stupidity on my part.

Joe
joemarcell is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 10-05-2004, 11:16 PM
Dale Hodge's Avatar
Skilled Talker

Posts: 63
Location: Syracuse, ny
Trades: 1
This should do the trick. I copied your code and added some of my own, so all you should have to do is copy my code.

Code:
#!/usr/bin/perl

##!/usr/bin/perl
#    chfeedback.pl Feedback Form Perl Script Ver 2.01
#    Generated by thesitewizard.com's Feedback Form Wizard.
#    Copyright 2000-2004 by Christopher Heng. All rights reserved.
#
#				http://www.aberdeendesign.co.uk
#


# ---------- USER CONFIGURATION SECTION ---------------
# Before this script will do anything useful, the following
# variables must be set.
#
# MANDATORY VARIABLES
# $mailprog - the location of your mail program and the parameters
#           to pass to it.
#			eg $mailprog = "/usr/lib/sendmail" ;
# $mailto - email address where the feedback will be sent
#           eg, $mailto = 'yourname@example.com' ;
# $subject - the subject line in the email sent by the feedback form
#           eg $subject = "Feedback Form" ;
#
# $formurl - the URL of your feedback form
#           eg $formurl = "http://www.example.com/feedback.html" ;
# $thankyouurl - the URL of your thank you page
#           eg $thankyouurl = "http://www.example.com/thanks.html" ;
# $errorurl - the URL of your error page
#           eg $errorurl = "http://www.example.com/error.html" ;


$mailprog = "/usr/lib/sendmail" ;
$mailto = 'info@aberdeendesign.co.uk' ;
$subject = "Contact Form" ;
$formurl = "http://www.aberdeendesign.co.uk/html/contact_form.html" ;
$errorurl = "http://www.aberdeendesign.co.uk/html/contact_error.html" ;
$thankyouurl = "http://www.aberdeendesign.co.uk/html/thank_you.html" ;


# ---------- END OF USER CONFIGURATION SECTION ------------

# ---------- functions -----------
sub redirect_url {
	my ( $url )	= shift ;
	print "Location: $url\n\n" ;
}

sub parse_form_data {
	my ($request_method, $input_string, $content_length) ;
	my (@vars, $indiv_var, $name, $value);
	my (%form) ;

	$request_method	= $ENV{'REQUEST_METHOD'} ;
	$content_length	= $ENV{'CONTENT_LENGTH'} ;

	# load the entire string into $input_string
	if ($request_method	=~ /post/i) {
		$input_string	= "" ;
		read( STDIN, $input_string, $content_length ) ;
	}
	else {
		$input_string	= $ENV{ 'QUERY_STRING' };
	}
	unless (defined $input_string) {
		$input_string	= "" ;
	}

	# put all the variable pairs (name=value) into an array
	@vars	= split( /&/, $input_string );

	# process each individual name, value pair, putting them
	# into a hash for easy access
	foreach $indiv_var ( @vars ) {

		# separate the pair
		($name, $value)	= split( /=/, $indiv_var, 2 );

		# translate encoding
		$name	=~ s/%([\da-fA-F]{2})/pack("C", hex($1))/eg;
		$name	=~ tr/+/ /;
		unless (defined $value) {
			# just in case there was no equals as in ISINDEX
			$value	= "" ;
		}
		$value	=~ s/%([\da-fA-F]{2})/pack("C", hex($1))/eg;
		$value	=~ tr/+/ /;

		# put the pair in the hash for easy access
		$form{$name}	= $value ;
	}

	return wantarray ? %form : undef ;
}

sub send_email {
	my ($mailprog, $email, $name, $mailto, $subject, $message) = @_ ;

	if (open MAIL, "|$mailprog -t") {
		print MAIL "To: $mailto\n" ;
		print MAIL "From: \"$name\" <$email>\n" ;
		print MAIL "Reply-To: \"$name\" <$email>\n" ;
		print MAIL "X-Mailer: chfeedback.pl 2.01\n" ;
		print MAIL "Subject: $subject\n\n" ;
		print MAIL $message ;
		close MAIL ;
	}
	# ignore fails, just don't do anything

	return ;
}

# ----------- main program ------

my %form = parse_form_data();

my $email ;
if (exists $form{"email"}) {
	$email	= $form{"email"} ;
}
else {
	redirect_url( $formurl );
	exit ;
}
if ($email eq "") {
	redirect_url( $errorurl );
	exit ;
}

my $name = $form{"name"} ;
if ($name eq "") {
	redirect_url( $errorurl );
	exit ;
}

my $comments = $form{'comments'} ;
if ($comments eq "*****") {
	redirect_url( $errorurl );
	exit ;
}

my $phone = $form{'phone'} ;
if ($phone eq "") {
	redirect_url( $errorurl );
	exit ;
}

my $businessname = $form{'businessname'} ;
if ($businessname eq "*****") {
	redirect_url( $errorurl );
	exit ;
}

$tick1 = $form{'1'} ;
if ($tick1) {
	$tick1 = "True";
}

else {
$tick1="False";
}
	
$tick2 = $form{'2'} ;
if ($tick2) {
	$tick2 = "True";
}

else {
$tick2="False";
}
	
$tick3 = $form{'3'} ;
if ($tick3) {
	$tick3 = "True";
}

else {
$tick3="False";
}
	
$tick4 = $form{'4'} ;
if ($tick4) {
	$tick4 = "True";
}

else {
$tick4="False";
}
	
$tick5 = $form{'5'} ;
if ($tick5) {
	$tick5 = "True";
}

else {
$tick5="False";
}
	
$tick6 = $form{'6'} ;
if ($tick6) {
	$tick6 = "True";
}

else {
$tick6="False";
}
	
$tick7 = $form{'7'} ;
if ($tick7) {
	$tick7 = "True";
}

else {
$tick7="False";
}
	
$tick8 = $form{'8'} ;
if ($tick8) {
   $tick8 = "True";
}

else {
$tick8="False";
};							

my $http_referer = $ENV{ 'HTTP_REFERER' };
my $message	=
	"This message was sent from:\n" .
	"$http_referer\n\n" .
	"------------------------------------------- Details --------\n\n" .
	"I am interested in :\n\n" .
	"Web Design - $tick1\n" .
	"CAD Work - $tick2\n" .
	"Catalogue Design - $tick3\n" .
	"Logo Design - $tick4\n" .
	"Digital Photography - $tick5\n\n" .
	"I represent a :\n\n" .
	"Business - $tick6\n" .
	"Club/Association - $tick7\n" .
	"Personal Cause - $tick8\n\n" .
   "Name:\n" .
	"$name\n\n" .
	"Email:\n" .
	"$email\n\n" .
	"Business Name:\n" .
	"$businessname\n\n" .
	"Telephone No:\n" .
	"$phone\n\n" .
	"Additional Comments:\n" .
	$comments . 
	"\n\n------------------------------------------------------------\n" ;
	
send_email ( $mailprog, $email, $name, $mailto, $subject, $message );
redirect_url( $thankyouurl );
Let me know how this worked out for you.

Last edited by Dale Hodge; 10-06-2004 at 12:40 AM..
Dale Hodge is offline
Reply With Quote
View Public Profile
 
Old 10-06-2004, 10:29 AM
Average Talker

Posts: 15
Trades: 0
Thank you soooo much Dale, you have saved me ALOT of time. The form works perfectly!!

If you ever need anything, you know where to find me.

Thanks again,

Joe
joemarcell is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Checkboxes in CGI formmails query
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.36120 seconds with 12 queries