<?php /* Make sure this part is at the top */ error_reporting(E_ALL & ~E_NOTICE); session_start(); ?> <?php // call the lib.. require_once('recaptchalib.php'); // Get a key from http://recaptcha.net/api/getkey $publickey = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; $privatekey = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; # was there a reCAPTCHA response? if ($_POST["submit"]) { $response = recaptcha_check_answer($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); if ($response->is_valid) { echo "Yes, that was correct!"; } else { # set the error code so that we can display it #echo "Eh, That wasn't right. Try Again."; } } ?> <form id="form1" name="form1" method="post" action=""> <div align="right"> <table width="544" border="0"> <tr> <td><strong>Type Any 5 Numbers</strong></td> <td><div align="right"><span id="sprytextfield2"> <input type="text" name="text1" id="text1" /> <span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldMaxValueMsg">The entered value is greater than the maximum allowed.</span><span class="textfieldMinValueMsg">The entered value is less than the minimum required.</span><span class="textfieldMinCharsMsg">Minimum number of characters not met.</span><span class="textfieldMaxCharsMsg">Exceeded maximum number of characters.</span></span></div></td> </tr> <tr> <td width="297"><strong>Title for your MinMu</strong></td> <td width="237"><div align="right"> <input name="title" type="text" id="title" value="<? echo $_GET['title']; ?>" /> </div></td> </tr> <tr> <td height="16"><strong>Your URL Title:</strong> (Alphanumeric, No Spaces!)</td> <td><div align="right"><span id="urltitle"> <input type="text" name="urltitle" id="urltitle" value="<? if ($_GET['taken'] == "yes") { ?><? echo $_GET['urltitle']; ?><? echo $random = rand(0, 100); ?><? } ?>" /> </span> <div class="username_exists" id="username_exists"></div> <span><span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldMinCharsMsg">Minimum number of characters not met.</span><span class="textfieldMaxCharsMsg">Exceeded maximum number of characters.</span></span></div></td> </tr> <tr> <td colspan="2"><? if ($_GET['taken'] == "yes") { ?><strong class="sorrytaken">Sorry that URL Title has been taken. We've changed it slighty, if your happy with the changes reclick generate Minmu Button. Sorry for the trouble!</strong><? } ?><div align="right"></div></td> </tr> <tr> <td height="16" colspan="2"><textarea name="data" cols="45" rows="10" class="formey" id="data" style="width:530px"><? echo $_SESSION['finaldata']; ?></textarea></td> </tr> <tr> <td height="16" colspan="2"><div align="right"> <?php echo recaptcha_get_html($publickey, $error); ?> <input name="generate" type="hidden" id="generate" value="true" /> <input name="id" type="hidden" id="id" value="<? echo genRandomString() ?>" /> <input type="submit" name="button" id="button" value="Generate!" /> </div></td> </tr> </table> </div> </form> PHP: Hi guys, can anyone advice me how to integrate recaptcha on my form? Tried it so far even without entering recaptcha, the form goes submitted just fine.
else { # set the error code so that we can display it #echo "Eh, That wasn't right. Try Again."; } Else portion of code is doing nothing. Add error message here or redirect to error message page. Form will be submitted in any case. Accept form values in the following 'if statement'. This if statement will execute only when captcha is correct. if ($response->is_valid) { echo "Yes, that was correct!"; // Save form data to db or whatever you want. }
I wrote this blog post few year ago, you can check this. Its very simple to follow and hope you can integrate reCaptcha by following it. http://atik97.wordpress.com/2010/11/26/use-recaptcha-in-your-php-scripts/