# check ReCaptcha if($vericode) { $CaptchaPath = $modx->config["base_path"].'assets/snippets/recaptcha/'; # Set Captcha Snippet Path $privatekey = "--- my private key ------"; # Set Private Key # Set Snippet Paths require_once($CaptchaPath."recaptchalib.php"); $resp = recaptcha_check_answer ($privatekey, # Check the Recaptcha answer generated in the form $_SERVER["REMOTE_ADDR"], $fields["recaptcha_challenge_field"], $fields["recaptcha_response_field"]); if ($resp->is_valid) { return; // echo "Your Captcha just validated!"; } else { $vMsg[count($vMsg)]= "(reCAPTCHA said: " . $resp->error . ")" . "<br /> Please re-select the recipients you wish to send to!"; // This died! } }
$server = "http://api.recaptcha.net"; $pubkey = "-- my public key ---"; $errorpart = ""; if ($error) { $errorpart = "&error=" . $error; } return '<script type="text/javascript" src="'. $server . '/challenge?k=' . $pubkey . $errorpart . '"></script> <noscript> <iframe src="'. $server . '/noscript?k=' . $pubkey . $errorpart . '" height="300" width="500" frameborder="0"></iframe><br/> <textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea> <input type="hidden" name="recaptcha_response_field" value="manual_challenge"/> </noscript>';
# are we submitting the page? if ($_POST["submit"]) { $resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); if ($resp->is_valid) { echo "You got it!"; # in a real application, you should send an email, create an account, etc } else { die ("reCAPTCHA failed") , but using the error message is # more user friendly $error = $resp->error;
Sorry if I seem to have a bit of a one tracked mind on this one BobRay....
I am kinda stubborn like that
[!recaptcha_snippet_2? &email=`--a valid email addy--` &tpl=`recaptcha_form_2` &captchaLibrary=`assets/snippets/recaptcha/recaptchalib.php` &captchaKeyPublic=`-- my public key --` &captchaKeyPrivate=`--my private key--`!]
<html> <body> <form action="" method="post"> [!recaptcha_snippet!] <br/> <input type="submit" value="submit" /> </form> </body> </html>
<script type=\"text/javascript\"> var RecaptchaOptions = { theme : 'custom' custom_theme_widget: 'recaptcha_widget' }; </script> [!echeckField!] [!eForm? &formid=`your form id` &subject=`subject` &tpl=`your template` &ccsender=`1` &eFormOnValidate=`checkField` &vericode=`1` &report=`your reportfom` &thankyou=`your thanks form` !]
function checkField(&$fields,&$vMsg,&$rMsg) { if(!empty($fields['Name2'])) { return false; } else { return; } }
/********** Captcha Styling **********/ #divrecaptcha{ font-size:13px; font-family: Verdana, helvetica, sans-serif; text-align:right; } #divrecaptcha controls{ width: 170px; font-size:10px; font-family: Verdana, helvetica, sans-serif; } #recaptcha_image{ background:#f9f9f9; border:1px solid #e0e0e0; width: 250px; margin-top: 20px; float:right; } #recaptcha_response_field { width:300px; border:1.5px solid #9898F1; font:14px Verdana, helvetica, sans-serif; color: Black; font-weight:bold; margin-top: 20px; } #divrecaptchalogo { background:#fff url(images/recaptcha.gif); height: 86px; width: 161px; float: left; } #divrecaptcha a{ font-size:10px; font-family:Verdana, helvetica, sans-serif; text-decoration:none; color:#3366ff; } #divrecaptcha a:hover{ color:#333; text-decoration:underline; } #divhidecaptcha { position:absolute; left:-100px; top:-200px; width:1px; height:1px; overflow:hidden; } .fun { position:absolute; text-decoration:underline; background-color:#CC0000; left:0px; top:-500px; width:1px; height:1px; overflow:hidden; }