Jump to content

CGI Script to proccess form


holmedwa04

Recommended Posts

Hi,Long time no see, for many of you, I am not sure whether this is in the right place, so please do move it if not, I just couldn't find a section on CGI.I have been working on a CGI and going through some tutorials on this website. I have got a script of this tutorial and got it working with a mini form if you like, here is the link:http://home.btconnect.com/shapemakingclub/...k/feedback.htmlI then continued with the tutorials and started to adapt the script to suite my guestbook, once I had finished my script, I tested it but it now doesn't work, here is a link to the page that requires the script, and if you fill it out, you will see the error that come up at the end:http://home.btconnect.com/shapemakingclub/addpost.htmlThis is the HTML code for the page:

<html><head><title>Add Post to Guestbook</title><meta name="keywords" content=""/></head><LINK rel="stylesheet" type="text/css" href="stylesheet.css"><body bgcolor="#000066" link="blue" vlink="blue"><font size="3"><font face="Arial"><font color="black"><center><table border="0" cellpadding="100" cellspacing="0" width="85%" bordercolor="#000000" bgcolor="#FFFFFF"><tr><td><BR><font size="5"> <center><b><u>Add Post to Guestbook</u></b><BR><BR></center><font size="2">If you would like to add a post to Shape Making Club guestbook please continue by filling out the form below, no email address is required to post a message on this guestbook.<BR><BR>Please note that if your name/nickname is not provided, post will not be submitted.  Posts will not be submitted until they have been moderated, moderating of posts includes the following, checking for any meaningless, worthless, abusive, vulgar, hateful, harassing, obscene, profane, sexually oriented, threatening, invasive of a person's privacy, or otherwise in violation of ANY law. You also agree not to post any copyrighted material unless the copyright is owned by you or you have consent from the owner of the copyrighted material. Spam, flooding, advertisements, chain letters, pyramid schemes, and solicitations are also inappropriate to this guestbook.<BR><BR><FORM METHOD=POST ACTION="../cgi-bin/guestbook.cgi"><table border="0" width="100%"><tr><td height="40"><font size="2">Name / Nickname:</td></tr><tr><td height="40"><INPUT TYPE="text" NAME="Guests Name" SIZE="30"></td></tr><tr><td height="40"><font size="2">Post:</td></tr><tr><td><TEXTAREA NAME="Guests Post" ROWS="10" COLS="120" style="font-family: arial;" onfocus="if (this.value=='Add Your Message Here.') {this.value='';}" onblur="if (this.value=='') {this.value='Add Your Message Here.';}">Add Your Message Here.</TEXTAREA></td></tr><tr><td height="40"><center><INPUT TYPE="submit" VALUE="Submit Post" onclick="window.location='thankyou.html';">   <INPUT TYPE="reset" VALUE="Clear Post"></center></td></tr></form></table><BR>N.B.  A warning message may appear when you click submit post, this is asking if you would like to continue, click yes and yes again to both warning messages.  Please note that moderating of posts may take anything up to a week to process, please do not submit a post more than once.<BR><BR><p style="background: #fcfbff; border: 1px dashed silver; padding: 8px; font-family: Arial"><em>Depressingly Necessary Privacy Policy:</em><br />Your privacy is always important and because we know it is so important any of your details will never be given out to any third parties or sold to anyone, for more information on this matter please visit our <a href="privacypolicy.html">Privacy Policy</a>.</p><BR><center><BR><form> <input type="Button" value="Back" onclick="history.back()"> </form><BR>______________________________________________________<BR><font size=1>Edward Holmes, SMC @ CCMS, <a href="mailto:shapemakingclub@btconnect.com">shapemakingclub@btconnect.com</a></center></td></tr></table></center></body></html>

I don't think that there is anything wrong with this code, then this is my script:

#!/usr/bin/perluse CGI::Carp qw(fatalsToBrowser);# The following accepts the data from the form and splits it into its component partsif ($ENV{'REQUEST_METHOD'} eq 'POST') {	read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});		@pairs = split(/&/, $buffer);		foreach $pair (@pairs) {		($name, $value) = split(/=/, $pair);		$value =~ tr/+/ /;		$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;		$FORM{$name} = $value;	}# Then sends the email open (MESSAGE,"| /usr/sbin/sendmail -t");  print MESSAGE "To: shapemakingclub\@btconnect.com\n";  print MESSAGE "From: " . $FORM{name} . ", reader\n";  print MESSAGE "Reply-to: " . $FORM{email} . "(" . $FORM{name} . ")\n";		print MESSAGE "Subject: Feedback from $FORM{name} \n\n";		print MESSAGE "Guests Name: $FORM{Guests Name}\n\n";	print MESSAGE "Post: $FORM{Guests Post}\n\n";close (MESSAGE);&thank_you; #method call} #The code then goes on to generate the thank-you pagesub thank_you {print "Content-type: text/html\n\n";print <<StartHTML;	<html><head><title>Thank-you</title><meta name="keywords" content=""/></head><LINK rel="stylesheet" type="text/css" href="stylesheet.css"><body bgcolor="#000066" link="blue" vlink="blue"><font size="3"><font face="Arial"><font color="black"><center><table border="0" cellpadding="100" cellspacing="0" width="85%" bordercolor="#000000" bgcolor="#FFFFFF"><tr><td><font size="5"> <center><b><u>Thank You</u></b><BR><BR></center><font size="2">Thank You for submitting a post to the Shape Making Club Guestbook, whilst we try to submit your post as soon as possible, moderating of your post may take anything up to a week.  Please do be patient, if your post has not been submitted after a week it is because it does not comply with the rules of our guestbook.		StratHTML;	print "<p>You Wrote:</p>\n\n";	print "<blockquote><em>$FORM{Guests Post}</em></blockquote>\n\n";	print <<EndHTML;	To return to our guestbook please <a href="guestbook.html">Click Here</a>.<BR><BR><BR><center><form><button onclick="location.href='index.html'">Home</button></form><BR>______________________________________________________<BR><font size="1"><font face="Arial"><font color="black">Edward Holmes, SMC \@ CCMS, <a href="mailto:shapemakingclub\@btconnect.com">shapemakingclub\@btconnect.com</a></center></td></tr></table></center></body></html>EndHTML;exit(0);}

There is one bit in the script that I don't get what is for, because it doesn't actually PRINT this in the email: print MESSAGE "To: shapemakingclub\@btconnect.com\n"; print MESSAGE "From: " . $FORM{name} . ", reader\n"; print MESSAGE "Reply-to: " . $FORM{email} . "(" . $FORM{name} . ")\n"; print MESSAGE "Subject: Feedback from $FORM{name} \n\n";And also, in the bit that generates thankyou page, I am not sure if "EndHTML" and "StartHTML" are right, because in the error it is complaining about something near here.Any help would be greatly appreciated, I have also changed the CHMOD in my FTP software when uploading the script.

Link to comment
Share on other sites

No, I used to get an error message when the form was filled out. However I have spoken to the person who made the tutorials on MSN and he has helped me to resolve the problem. I just need to change some coding, because for osme reason the code that was there wasn't working. I have now got a guestbook that doesn't require a client side email to be sent! I will hopefully be appling a similar script to my feedback form soon.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...