Jump to content

Captcha


ben3001
 Share

Recommended Posts

Ok i have been reading loads of tutorials on making a captcha for my form but i have failed. The tutorial that i keeps coming up is a captcha that one you type the verification code it then lets you go to a specified form page where to your details etc and then submits. To be honest i find this method very time consuming for the user and am wondering how can i apply a captcha test for my form.I have looked through this forum and found limited help, someone in one topic has actually deleted all there help they gave (not nice)ThanksBenThe Php behind the form is:

<?php $name=$_POST['Name'];$Email=$_POST['Email'];$Comment=$_POST['Comment'];$Subject=$_POST['subject'];$counter=0;function printit(){if ( isset ($_POST['submit'])){$incorrectCustomer="";$incorrectEmail="";$incorrectDate="";$incorrectComment="";if($_POST['Name']==null){$incorrectCustomer="<span style='color:#FF0000'> * Required</span>";}else{$incorrectCustomer="";}if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3}){:content:}quot;, $_POST['Email'])){$incorrectEmail="";} else {$incorrectEmail="<span style='color:#FF0000'> * Required</span>";}if($_POST['Comment']==null){$incorrectComment="<span style='color:#FF0000'> * Required</span>";}else{$incorrectComment="";}}else {}print '<span class=style4>Enquires</span><p>Problem with the site? Need more information? Complete the form below, if you have entered your email address correctly you should recieve an automated reply confirming your query has been recieved . All emails are replied to within 24 hours.</p><script language="JavaScript"><!--document.myForm.myField.disabled=true;//--></script><form name="Contact Us" action="design2.php" method="post"><table style= width="100%" border="0" cellpadding="3" cellspacing="1"><tr><td width="20%"><p align="left">Website design regarding:</p></td><td width="80%"><input class="border" type="text" disabled onFocus="if (this.disabled) this.blur()" name="subject" size="35" maxlength="100" value="sitehere""' . $_POST['subject'] . '"/>';print '</td></tr><tr><td width="20%">Name:</td><td width="80%"><input class="border" type="text" name="Name" size="25" maxlength="35" value="' . $_POST['Name'] . '" />';print "$incorrectCustomer";print '</td></tr><tr><td>Email:</td><td><input class="border" type="text" name="Email" size="35" maxlength="100" value="' . $_POST['Email'] . '"/>';print "$incorrectEmail";print '</td></tr><tr><td>Enquiry</td><td><textarea class="border" name="Comment" rows="3" cols="41">' . $_POST['Comment'] . '</textarea>';print "$incorrectComment";print '</td></tr><table border="0" width="100%"><tr><td width="100%"><input type="submit" name="submit" value="Send" /> <input type="reset" name="Reset" value="Reset" /></td></tr></table></form></table>';}if ( isset ($_POST['submit'])) {$validEmail=true;$validNumber=true;if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3}){:content:}quot;, $Email)){ }else {$validEmail=false;}if(($name==null)||($validEmail==false)||($Comment==null)) { print"";printit();}else mail("$Email","Auto Reply Website Design: ","print "<span class=style4>Thank you for your enquiry</span><p>Comments are always welcomed and replied to within 2-3 days.</br></font><p>The email you sent is shown below, you should of received an email confirming I have recieved your enquiry:</p> <strong><p>Website design regarding:</strong> <p/><strong><p>Name:</strong> $name<p/><strong><p>Email address:</strong> $Email</p> <strong><p>Enquiry:</strong> $Comment</p>"; }} else { // Display the form.printit();}?>

Edited by ben3001
Link to comment
Share on other sites

I currently just have the form.I was going to use the premaid Captcha but thought its very unprofessional. http://www.captcha.net/I then looked at this following captcha http://www.captcha.biz but there example made you first veify your a human then goto the form and type your info which as said above is not user friendly.Im look for a way to add a captcha within the form thats been created.Thanks B.

What have you done so far? Have you already done work with a captcha? Do you just have the form and now you want to add a captcha to it? I know there is a huge list of captcha implementations on the wikipedia page.
Link to comment
Share on other sites

The only tutorial you are going to find for implementing a captcha will be documentation for a specific one on how to set it up. A captcha is just a form though, and you have a form too, so implementing the thing is about as easy as taking the form created by the captcha, adding the elements into your own form, and then using the processing code for the captcha in your own processing code to make sure they got the correct answer. I can't be any more specific then that without seeing all the code involved, but that is what I would do.You can also try this one, it looks pretty good:http://recaptcha.net/learnmore.html

Link to comment
Share on other sites

Im looking at this code they have given.how can this be implemented with the code i have provided at the top?i have now got a api key from the siteThis sample if the users type the right words in just gets a messgae saying you got it or error

<html>  <body>    <form action="" method="post"><?phprequire_once('recaptchalib.php');// Get a key from [url="http://recaptcha.net/api/getkey"]http://recaptcha.net/api/getkey[/url]$publickey = "";$privatekey = "";# the response from reCAPTCHA$resp = null;# the error code from reCAPTCHA, if any$error = null;# was there a reCAPTCHA response?if ($_POST["recaptcha_response_field"]) {        $resp = recaptcha_check_answer ($privatekey,                                        $_SERVER["REMOTE_ADDR"],                                        $_POST["recaptcha_challenge_field"],                                        $_POST["recaptcha_response_field"]);        if ($resp->is_valid) {                echo "You got it!";        } else {                # set the error code so that we can display it                $error = $resp->error;        }}echo recaptcha_get_html($publickey, $error);?>    <br/>    <input type="submit" value="submit" />    </form>  </body></html>

Link to comment
Share on other sites

This line displays the captcha in the form:

echo recaptcha_get_html($publickey, $error);

This part checks if it is correct:

if ($_POST["recaptcha_response_field"]) {		$resp = recaptcha_check_answer ($privatekey,										$_SERVER["REMOTE_ADDR"],										$_POST["recaptcha_challenge_field"],										$_POST["recaptcha_response_field"]);		if ($resp->is_valid) {				echo "You got it!";		} else {				# set the error code so that we can display it				$error = $resp->error;		}}

Link to comment
Share on other sites

You need to include the required files on your page so that you have access to the classes they create. The line to show the captcha you put wherever you want it in the form, in a td or div or whatever. The other code with the if statement you put around your form processing code. The if statement checks if they got the captcha correct, so you can use that to decide if you want to continue processing the form or show an error message.

Link to comment
Share on other sites

Anywhere i put the line to show the captcha wherever I want it in the form i keep getting the same error message

Fatal error: Call to undefined function: recaptcha_get_html() in /content/StartupHostPlus/a/q/aquatic-management.org/web/cap/design2.php on line 43
you can see it here: http://www.aquatic-management.org/cap/design2.phpThe full code:
<?php $name=$_POST['Name'];$Email=$_POST['Email'];$Comment=$_POST['Comment'];$Subject=$_POST['subject'];$counter=0;function printit(){if ( isset ($_POST['submit'])){$incorrectCustomer="";$incorrectEmail="";$incorrectDate="";$incorrectComment="";if($_POST['Name']==null){$incorrectCustomer="<span style='color:#FF0000'> * Required</span>";}else{$incorrectCustomer="";}if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST['Email'])){$incorrectEmail="";} else {$incorrectEmail="<span style='color:#FF0000'> * Required</span>";}if($_POST['Comment']==null){$incorrectComment="<span style='color:#FF0000'> * Required</span>";}else{$incorrectComment="";}}else {}echo recaptcha_get_html($publickey, $error);print '<span class=style4>Enquires</span><p>Problem with the site? Need more information? Complete the form below, if you have entered your email address correctly you should recieve an automated reply confirming your query has been recieved . All emails are replied to within 24 hours.</p><script language="JavaScript"></script><form name="Contact Us" action="design2.php" method="post"><table style= width="100%" border="0" cellpadding="3" cellspacing="1"><tr><td width="20%"><p align="left">Website design regarding:</p></td><td width="80%"><input class="border" type="text" disabled onFocus="if (this.disabled) this.blur()" name="subject" size="35" maxlength="100" value="[url="http://www.aquatic-management.org/"]http://www.aquatic-management.org""'[/url] . $_POST['subject'] . '"/>';print '</td></tr><tr><td width="20%">Name:</td><td width="80%"><input class="border" type="text" name="Name" size="25" maxlength="35" value="' . $_POST['Name'] . '" />';print "$incorrectCustomer";print '</td></tr><tr><td>Email:</td><td><input class="border" type="text" name="Email" size="35" maxlength="100" value="' . $_POST['Email'] . '"/>';print "$incorrectEmail";print '</td></tr><tr><td>Enquiry</td><td><textarea class="border" name="Comment" rows="3" cols="41">' . $_POST['Comment'] . '</textarea>';print "$incorrectComment";print '</td></tr><table border="0" width="100%"><tr><td width="100%"><input type="submit" name="submit" value="Send" /> <input type="reset" name="Reset" value="Reset" /></td></tr></table></form></table>';}if ($_POST["recaptcha_response_field"]) {$resp = recaptcha_check_answer ($privatekey,$_SERVER["REMOTE_ADDR"],$_POST["recaptcha_challenge_field"],$_POST["recaptcha_response_field"]);if ($resp->is_valid) {echo "You got it!";} else {# set the error code so that we can display it$error = $resp->error;}}if ( isset ($_POST['submit'])) {$validEmail=true;$validNumber=true;if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $Email)){ }else {$validEmail=false;}if(($name==null)||($validEmail==false)||($Comment==null)) { print"";printit();}else { mail("[email=b_e_n04@hotmail.com]b_e_n04@hotmail.com","Website[/email] Design: [url="http://www.aquatic-management.org/"]http://www.aquatic-management.org[/url]","From: $name Email Address: $Email Message: $Comment","From:$Email");mail("$Email","Auto Reply Website Design: [url="http://www.aquatic-management.org/"]http://www.aquatic-management.org[/url]","Dear: $nameThank you for contacting me regarding [url="http://www.aquatic-management.org/"]http://www.aquatic-management.org[/url]. Your enquiry is shown below. '$Comment'I attempt to respond to all emails with in 24 hours however, due to busy times this may take longer.Once again thank-you for your enquiry.Ben Davies","From:b_e_n04@hotmail.com");print "<span class=style4>Thank you for your enquiry</span><br><p>Comments are always welcomed and replied to within 2-3 days.</br></font><p>The email you sent is shown below, you should of received an email confirming I have recieved your enquiry:</p> <strong><p>Website design regarding:</strong> [url="http://www.aquatic-management.org%3cp/"]http://www.aquatic-management.org<p/[/url]><strong><p>Name:</strong> $name<p/><strong><p>Email address:</strong> $Email</p> <strong><p>Enquiry:</strong> $Comment</p>"; }} else { // Display the form.printit();}?>

Link to comment
Share on other sites

Add the code that includes the recaptcha library. I'm not sure if they sent you a private key or not, but if you had to sign up with them I'm sure they gave you whatever info needs to be there.

require_once('recaptchalib.php');// Get a key from http://recaptcha.net/api/getkey$publickey = "";$privatekey = "";# the response from reCAPTCHA$resp = null;# the error code from reCAPTCHA, if any$error = null;

Link to comment
Share on other sites

Thanks for helping.i have added all the necessary code however the form is just as before it works but no Captcha. http://www.aquatic-management.org/cap/design2.phpForm code:

<?php 		$name=$_POST['Name'];$Email=$_POST['Email'];$Comment=$_POST['Comment'];$Subject=$_POST['subject'];$counter=0;require_once('recaptchalib.php');// Get a key from [url="http://recaptcha.net/api/getkey"]http://recaptcha.net/api/getkey[/url]$publickey = "6LfYGAAAAAAAADhqTaxwzNkGsYPQzDTxZSmaqoi6";$privatekey = "6LfYGAAAAAAAAEuz8HUoMZyNS-cFXKw0TSE0QS3t";# the response from reCAPTCHA$resp = null;# the error code from reCAPTCHA, if any$error = null;function printit(){if ( isset ($_POST['submit'])){$incorrectCustomer="";$incorrectEmail="";$incorrectDate="";$incorrectComment="";if($_POST['Name']==null){$incorrectCustomer="<span style='color:#FF0000'> * Required</span>";}else{$incorrectCustomer="";}if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST['Email'])){$incorrectEmail="";} else {$incorrectEmail="<span style='color:#FF0000'> * Required</span>";}if($_POST['Comment']==null){$incorrectComment="<span style='color:#FF0000'> * Required</span>";}else{$incorrectComment="";}}else {}print '<span class=style4>Enquires</span>        <p>Problem with the site? Need more information? Complete the form below, 		if you have entered your email address correctly you should recieve an automated reply confirming 		your query has been recieved . All emails are replied to within 24 hours.</p><script language="JavaScript"><!--document.myForm.myField.disabled=true;//--></script><form name="Contact Us" action="design2.php" method="post"><table style= width="100%" border="0" cellpadding="3" cellspacing="1"><tr><td width="20%"><p align="left">Website design regarding:</p></td><td width="80%"><input class="border" type="text" disabled onFocus="if (this.disabled) this.blur()" name="subject" size="35" maxlength="100" value="http://www.aquatic-management.org""' . $_POST['subject'] . '"/>';print  '</td></tr><tr><td width="20%">Name:</td><td width="80%"><input class="border" type="text" name="Name" size="25" maxlength="35" value="' . $_POST['Name'] . '" />';print "$incorrectCustomer";print '</td> </tr><tr><td>Email:</td><td><input class="border" type="text" name="Email" size="35" maxlength="100" value="' . $_POST['Email'] . '"/>';print "$incorrectEmail";print '</td></tr><tr><td>Enquiry</td><td><textarea class="border" name="Comment" rows="3" cols="41">' . $_POST['Comment'] . '</textarea>';print "$incorrectComment";print '</td></tr><table border="0" width="100%">  <tr>      <td width="100%"><input type="submit" name="submit" value="Send" /> <input type="reset" name="Reset" value="Reset" /></td>  </tr></table></form></table>';}if ($_POST["recaptcha_response_field"]) {        $resp = recaptcha_check_answer ($privatekey,                                        $_SERVER["REMOTE_ADDR"],                                        $_POST["recaptcha_challenge_field"],                                        $_POST["recaptcha_response_field"]);        if ($resp->is_valid) {                echo "You got it!";        } else {                # set the error code so that we can display it                $error = $resp->error;        }				echo recaptcha_get_html($publickey, $error);}if ( isset ($_POST['submit'])) {$validEmail=true;$validNumber=true;if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $Email)){  }else {$validEmail=false;}if(($name==null)||($validEmail==false)||($Comment==null)) {    echo recaptcha_get_html($publickey, $error);print"";printit();}else   {      mail("b_e_n04@hotmail.com","Website Design: [url="http://www.aquatic-management.org",""]http://www.aquatic-management.org","[/url]From: $name Email Address: $Email	 Message: $Comment","From:$Email");mail("$Email","Auto Reply Website Design: [url="http://www.aquatic-management.org",""]http://www.aquatic-management.org","[/url]Dear: $nameThank you for contacting me regarding [url="http://www.aquatic-management.org"]http://www.aquatic-management.org[/url]. Your enquiry is shown below. '$Comment'I attempt to respond to all emails with in 24 hours however, due to busy times this may take longer.Once again thank-you for your enquiry.Ben Davies","From:b_e_n04@hotmail.com");  print "<span class=style4>Thank you for your enquiry</span>   <br><p>Comments are always welcomed and replied to within 2-3 days.</br></font><p>The email you sent is shown below, you should of received an email confirming I have recieved your enquiry:</p>     <strong><p>Website design regarding:</strong> [url="http://www.aquatic-management.org<p/>"]http://www.aquatic-management.org<p/>[/url]<strong><p>Name:</strong> $name<p/><strong><p>Email address:</strong> $Email</p>  <strong><p>Enquiry:</strong> $Comment</p>        ";  }} else {       // Display the form.printit();}?>

Link to comment
Share on other sites

The code is pretty hard to read when it's formatted like that, so I've taken the liberty to reformat it. I also made some minor changes, you had some weird things like an empty if or else block, or the inline print statements or things like that. If you look at this version, you can notice that you only print the captcha if the form gets submitted and has errors.

<?php$name=$_POST['Name'];$Email=$_POST['Email'];$Comment=$_POST['Comment'];$Subject=$_POST['subject'];$counter=0;require_once('recaptchalib.php');// Get a key from http://recaptcha.net/api/getkey$publickey = "6LfYGAAAAAAAADhqTaxwzNkGsYPQzDTxZSmaqoi6";$privatekey = "6LfYGAAAAAAAAEuz8HUoMZyNS-cFXKw0TSE0QS3t";# the response from reCAPTCHA$resp = null;# the error code from reCAPTCHA, if any$error = null;function printit(){  if (isset ($_POST['submit']))  {	$incorrectCustomer = "";	$incorrectEmail = "";	$incorrectDate = "";	$incorrectComment = "";		if($_POST['Name'] == null)	  $incorrectCustomer = "<span style='color:#FF0000'> * Required</span>";	else	  $incorrectCustomer = "";	if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST['Email']))	  $incorrectEmail = "";	else	  $incorrectEmail = "<span style='color:#FF0000'> * Required</span>";	if($_POST['Comment'] == null)	  $incorrectComment = "<span style='color:#FF0000'> * Required</span>";	else	  $incorrectComment = "";  }  print '<span class=style4>Enquires</span>		  <p>Problem with the site? Need more information? Complete the form below,			  if you have entered your email address correctly you should recieve an automated reply confirming			  your query has been recieved . All emails are replied to within 24 hours.</p>  <script language="JavaScript"><!--  document.myForm.myField.disabled=true;  //--></script>  <form name="Contact Us" action="design2.php" method="post">  <table style= width="100%" border="0" cellpadding="3" cellspacing="1">  <tr>  <td width="20%"><p align="left">Website design regarding:</p></td>  <td width="80%"><input class="border" type="text" disabled onFocus="if (this.disabled) this.blur()" name="subject" size="35" maxlength="100" value="http://www.aquatic-management.org""' . $_POST['subject'] . '"/></td>  </tr>  <tr>  <td width="20%">Name:</td>  <td width="80%"><input class="border" type="text" name="Name" size="25" maxlength="35" value="' . $_POST['Name'] . '" />' . $incorrectCustomer . '</td>  </tr>  <tr>  <td>Email:</td>  <td><input class="border" type="text" name="Email" size="35" maxlength="100" value="' . $_POST['Email'] . '"/>' . $incorrectEmail . '</td>  </tr>  <tr>  <td>Enquiry</td>  <td><textarea class="border" name="Comment" rows="3" cols="41">' . $_POST['Comment'] . '</textarea>' . $incorrectComment . '</td>  </tr>  <table border="0" width="100%">	<tr>		<td width="100%"><input type="submit" name="submit" value="Send" /> <input type="reset" name="Reset" value="Reset" /></td>	</tr>  </table></form>  </table>  ';}if ($_POST["recaptcha_response_field"]) {  $resp = recaptcha_check_answer ($privatekey,								  $_SERVER["REMOTE_ADDR"],								  $_POST["recaptcha_challenge_field"],								  $_POST["recaptcha_response_field"]);  if ($resp->is_valid)  {	echo "You got it!";  }  else  {	# set the error code so that we can display it	$error = $resp->error;  }	echo recaptcha_get_html($publickey, $error);}if (isset ($_POST['submit'])){  $validEmail=true;  $validNumber=true;  if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $Email))	$validEmail=false;  if(($name==null)||($validEmail==false)||($Comment==null))  {	echo recaptcha_get_html($publickey, $error);	printit();  }  else  {	mail("b_e_n04@hotmail.com","Website Design: http://www.aquatic-management.org","From: $name\nEmail Address: $Email\nMessage: $Comment","From:$Email");	mail($Email,"Auto Reply Website Design: http://www.aquatic-management.org","Dear: $name\n\nThank you for contacting me regarding http://www.aquatic-management.org. Your enquiry is shown below.\n\n'$Comment'\n\nI attempt to respond to all emails with in 24 hours however, due to busy times this may take longer.\n\nOnce again thank-you for your enquiry.\n\nBen Davies","From:b_e_n04@hotmail.com");	print "<span class=style4>Thank you for your enquiry</span>	  <br><p>Comments are always welcomed and replied to within 2-3 days.</br></font>	  <p>The email you sent is shown below, you should of received an email confirming I have recieved your enquiry:</p>	  <strong><p>Website design regarding:</strong> http://www.aquatic-management.org<p/>	  <strong><p>Name:</strong> $name<p/>	  <strong><p>Email address:</strong> $Email</p>	  <strong><p>Enquiry:</strong> $Comment</p>";  }}else {	     // Display the form.  printit();}?>

Link to comment
Share on other sites

I didn't move anything in the code, I just cleaned it up a little. Instead of having a call to show the captcha HTML after you show the form, like this:

  if(($name==null) || ($validEmail==false) || ($Comment==null))  {	echo recaptcha_get_html($publickey, $error);	printit();  }

Just move the recaptcha_get_html function call inside the printit function, then whenever you show the form you'll also print out the captcha. You can add something like this:

  <tr>  <td>Verification:</td>  <td>' . recaptcha_get_html($publickey, $error) . '</td>  </tr>

Link to comment
Share on other sites

Now its performing as i have the incorrect api key, i definately have the right one.

<?php 		$name=$_POST['Name'];$Email=$_POST['Email'];$Comment=$_POST['Comment'];$Subject=$_POST['subject'];$counter=0;require_once('recaptchalib.php');// Get a key from [url="http://recaptcha.net/api/getkey"]http://recaptcha.net/api/getkey[/url]$publickey = "6LcFHwAAAAAAAFyCHo-h-t65VHyvye-yL9VDhFtY";$privatekey = "6LcFHwAAAAAAAE22y6Z62EprK2oyTg9NNjGVl07h";# the response from reCAPTCHA$resp = null;# the error code from reCAPTCHA, if any$error = null;function printit(){if ( isset ($_POST['submit'])){$incorrectCustomer="";$incorrectEmail="";$incorrectDate="";$incorrectComment="";if($_POST['Name']==null){$incorrectCustomer="<span style='color:#FF0000'> * Required</span>";}else{$incorrectCustomer="";}if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST['Email'])){$incorrectEmail="";} else {$incorrectEmail="<span style='color:#FF0000'> * Required</span>";}if($_POST['Comment']==null){$incorrectComment="<span style='color:#FF0000'> * Required</span>";}else{$incorrectComment="";}}else {}print '<span class=style4>Enquires</span>        <p>Problem with the site? Need more information? Complete the form below, 		if you have entered your email address correctly you should recieve an automated reply confirming 		your query has been recieved . All emails are replied to within 24 hours.</p><script language="JavaScript"><!--document.myForm.myField.disabled=true;//--></script><form name="Contact Us" action="design2.php" method="post"><table style= width="100%" border="0" cellpadding="3" cellspacing="1"><tr><td width="20%"><p align="left">Website design regarding:</p></td><td width="80%"><input class="border" type="text" disabled onFocus="if (this.disabled) this.blur()" name="subject" size="35" maxlength="100" value="http://www.aquatic-management.org""' . $_POST['subject'] . '"/>';print  '</td></tr><tr><td width="20%">Name:</td><td width="80%"><input class="border" type="text" name="Name" size="25" maxlength="35" value="' . $_POST['Name'] . '" />';print "$incorrectCustomer";print '</td> </tr><tr><td>Email:</td><td><input class="border" type="text" name="Email" size="35" maxlength="100" value="' . $_POST['Email'] . '"/>';print "$incorrectEmail";print '</td></tr><tr><td>Enquiry</td><td><textarea class="border" name="Comment" rows="3" cols="41">' . $_POST['Comment'] . '</textarea>';print "$incorrectComment";print '</td></tr><tr>  <td>Verification:</td>  <td>' . recaptcha_get_html($publickey, $error) . '</td>  </tr><table border="0" width="100%">  <tr>      <td width="100%"><input type="submit" name="submit" value="Send" /> <input type="reset" name="Reset" value="Reset" /></td>  </tr></table></form></table>';}if ($_POST["recaptcha_response_field"]) {        $resp = recaptcha_check_answer ($privatekey,                                        $_SERVER["REMOTE_ADDR"],                                        $_POST["recaptcha_challenge_field"],                                        $_POST["recaptcha_response_field"]);        if ($resp->is_valid) {                echo "You got it!";        } else {                # set the error code so that we can display it                $error = $resp->error;        }				echo recaptcha_get_html($publickey, $error);}if ( isset ($_POST['submit'])) {$validEmail=true;$validNumber=true;if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $Email)){  }else {$validEmail=false;}if(($name==null)||($validEmail==false)||($Comment==null)) {    print"";printit();}else   {      mail("b_e_n04@hotmail.com","Website Design: [url="http://www.aquatic-management.org",""]http://www.aquatic-management.org","[/url]From: $name Email Address: $Email	 Message: $Comment","From:$Email");mail("$Email","Auto Reply Website Design: [url="http://www.aquatic-management.org",""]http://www.aquatic-management.org","[/url]Dear: $nameThank you for contacting me regarding [url="http://www.aquatic-management.org"]http://www.aquatic-management.org[/url]. Your enquiry is shown below. '$Comment'I attempt to respond to all emails with in 24 hours however, due to busy times this may take longer.Once again thank-you for your enquiry.Ben Davies","From:b_e_n04@hotmail.com");  print "<span class=style4>Thank you for your enquiry</span>   <br><p>Comments are always welcomed and replied to within 2-3 days.</br></font><p>The email you sent is shown below, you should of received an email confirming I have recieved your enquiry:</p>     <strong><p>Website design regarding:</strong> [url="http://www.aquatic-management.org<p/>"]http://www.aquatic-management.org<p/>[/url]<strong><p>Name:</strong> $name<p/><strong><p>Email address:</strong> $Email</p>  <strong><p>Enquiry:</strong> $Comment</p>        ";  }} else {       // Display the form.printit();}?>

Link to comment
Share on other sites

I suppose i'd rather be pointed in the direction of a good tutorial rather then being done for me, then if i have any problems they will be delt with accordingly.
I was just reading through your topic's posts, and while searching for tutorials for my own problem trying to figure out how to allow users to upload a file to the site and have that file emailed to me with their contact information, I found a CAPTCHA tutorial. Webcheatsheet: CAPTCHAI keep posting my own problems with my codes, and thought I should try to give a little help too... Since I believe you should help others in order to get help yourself!I hope that helps a little/at all... :)
Link to comment
Share on other sites

Were are nearly there justsomeguy.the captcha form displays however, it seems as there is no point to it as you can just submit the form as normal without filling the captcha out and the form will submit.if you do enter the captcha it just prints You got it! and submits the form.@geekygirl thanks for the tut ill keep that in mind when im next thinking of doing another captcha.

Link to comment
Share on other sites

This is the code that checks the captcha:

if ($_POST["recaptcha_response_field"]) {  $resp = recaptcha_check_answer ($privatekey,										$_SERVER["REMOTE_ADDR"],										$_POST["recaptcha_challenge_field"],										$_POST["recaptcha_response_field"]);  if ($resp->is_valid) {	echo "You got it!";  } else {	# set the error code so that we can display it	$error = $resp->error;  }  echo recaptcha_get_html($publickey, $error);}

You need to move that code inside the block that gets executed when the form gets submitted. Right now it's sitting in the code on it's own, it's not in the code that gets executed when the form gets submitted. Look at the structure of the if statement there and integrate that into your own code. There is the if/else that checks if the captcha is correct, so use that to either bounce them back to the form if it is wrong, or execute the rest of your code if it is correct.

Link to comment
Share on other sites

i've added the code in the part where it gets executed when the form gets submitted but ive recieved this message

Parse error: syntax error, unexpected T_ELSE in /content/StartupHostPlus/a/q/aquatic-management.org/web/cap/design2.php on line 67
<?php         $name=$_POST['Name'];$Email=$_POST['Email'];$Comment=$_POST['Comment'];$Subject=$_POST['subject'];$counter=0;require_once('recaptchalib.php');// Get a key from [url="http://recaptcha.net/api/getkey"]http://recaptcha.net/api/getkey[/url]$publickey = "6LcFHwAAAAAAAFyCHo-h-t65VHyvye-yL9VDhFtY";$privatekey = "6LcFHwAAAAAAAE22y6Z62EprK2oyTg9NNjGVl07h";# the response from reCAPTCHA$resp = null;# the error code from reCAPTCHA, if any$error = null;function printit(){  global $publickey;if ( isset ($_POST['submit'])){$incorrectCustomer="";$incorrectEmail="";$incorrectDate="";$incorrectComment="";if($_POST['Name']==null){$incorrectCustomer="<span style='color:#FF0000'> * Required</span>";}else{$incorrectCustomer="";}if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST['Email'])){$incorrectEmail="";} else {$incorrectEmail="<span style='color:#FF0000'> * Required</span>";}if($_POST['Comment']==null){$incorrectComment="<span style='color:#FF0000'> * Required</span>";}else{$incorrectComment="";}}if ($_POST["recaptcha_response_field"]) {        $resp = recaptcha_check_answer ($privatekey,                                        $_SERVER["REMOTE_ADDR"],                                        $_POST["recaptcha_challenge_field"],                                        $_POST["recaptcha_response_field"]);        if ($resp->is_valid) {                echo "You got it!";        } else {                # set the error code so that we can display it                $error = $resp->error;        }                echo recaptcha_get_html($publickey, $error);else {}print '<span class=style4>Enquires</span>        <p>Problem with the site? Need more information? Complete the form below,         if you have entered your email address correctly you should recieve an automated reply confirming         your query has been recieved . All emails are replied to within 24 hours.</p><script language="JavaScript"><!--document.myForm.myField.disabled=true;//--></script><form name="Contact Us" action="design2.php" method="post"><table style= width="100%" border="0" cellpadding="3" cellspacing="1"><tr><td width="20%"><p align="left">Website design regarding:</p></td><td width="80%"><input class="border" type="text" disabled onFocus="if (this.disabled) this.blur()" name="subject" size="35" maxlength="100" value="http://www.aquatic-management.org""' . $_POST['subject'] . '"/>';print  '</td></tr><tr><td width="20%">Name:</td><td width="80%"><input class="border" type="text" name="Name" size="25" maxlength="35" value="' . $_POST['Name'] . '" />';print "$incorrectCustomer";print '</td> </tr><tr><td>Email:</td><td><input class="border" type="text" name="Email" size="35" maxlength="100" value="' . $_POST['Email'] . '"/>';print "$incorrectEmail";print '</td></tr><tr><td>Enquiry</td><td><textarea class="border" name="Comment" rows="3" cols="41">' . $_POST['Comment'] . '</textarea>';print "$incorrectComment";print '</td></tr><tr>  <td>Verification:</td>  <td>' . recaptcha_get_html($publickey, $error) . '</td>  </tr><table border="0" width="100%">  <tr>      <td width="100%"><input type="submit" name="submit" value="Send" /> <input type="reset" name="Reset" value="Reset" /></td>  </tr></table></form></table>';}if ( isset ($_POST['submit'])) {$validEmail=true;$validNumber=true;if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $Email)){  }else {$validEmail=false;}if(($name==null)||($validEmail==false)||($Comment==null)) {    print"";printit();}else   {      mail("b_e_n04@hotmail.com","Website Design: [url="http://www.aquatic-management.org",""]http://www.aquatic-management.org","[/url]From: $name Email Address: $Email     Message: $Comment","From:$Email");mail("$Email","Auto Reply Website Design: [url="http://www.aquatic-management.org",""]http://www.aquatic-management.org","[/url]Dear: $nameThank you for contacting me regarding [url="http://www.aquatic-management.org"]http://www.aquatic-management.org[/url]. Your enquiry is shown below. '$Comment'I attempt to respond to all emails with in 24 hours however, due to busy times this may take longer.Once again thank-you for your enquiry.Ben Davies","From:b_e_n04@hotmail.com");  print "<span class=style4>Thank you for your enquiry</span>   <br><p>Comments are always welcomed and replied to within 2-3 days.</br></font><p>The email you sent is shown below, you should of received an email confirming I have recieved your enquiry:</p>     <strong><p>Website design regarding:</strong> [url="http://www.aquatic-management.org<p/>"]http://www.aquatic-management.org<p/>[/url]<strong><p>Name:</strong> $name<p/><strong><p>Email address:</strong> $Email</p>  <strong><p>Enquiry:</strong> $Comment</p>        ";  }} else {       // Display the form.printit();}?>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...