Using recaptcha on php form within Wordpress template
Form changes
<form class="form" method="POST" action="index.php" onsubmit="return validateCaptcha()"><input type="hidden" name="valid" value="0" />
Below the form
<script type="text/javascript">function validateCaptcha(){ if ($('input[name="valid"]')) return true; if ($('input[name="recaptcha_response_field"]').val() == "") { alert("Fill in the captcha field"); return false } $.ajax({ url: "verify.php", type: "POST", async:"false", data: { recaptcha_response_field: $('input[name="recaptcha_response_field"]').val(), recaptcha_challenge_field: $('input[name="recaptcha_challenge_field"]').val() }, success: function(data){ if (data == "OK") { $('input[name="valid"]').val(1); $('.form').submit(); } else { alert(data); } }, error: function(){ alert("An error occured, please try again later"); } }); return false;};</script>
verify.php
if (!$resp->is_valid) { die ("The reCAPTCHA wasn't entered correctly. Go back and try it again. (reCAPTCHA said: " . $resp->error . ")");} else { echo "OK";}