I am new in PHP, jQuery and AJAX.
I am trying to implement new Google Recapcha.
It looks like -
After Click-
And After verified-
And the code of the index.php is-
<html>
<head>
<title>Google recapcha demo - Codeforgeek</title>
</head>
<body>
<h1>Google reCAPTHA Demo</h1>
<form id="comment_form" action="received.php" method="post">
<input type="email" placeholder="Type your email" size="40"><br><br>
<textarea name="comment" rows="8" cols="39"></textarea><br><br>
<!-- ---------------------------------------Capcha Start------------------------------------- -->
<script src='https://www.google.com/recaptcha/api.js'></script>
<?php $siteKey="6LdLqv8SAAAAADT3YEjm6ONCwnPD95frMSZ92Ftv" ?>
<div class="g-recaptcha" data-sitekey="<?php echo $siteKey; ?>"></div>
<!-- ----------------------------------------Capcha End------------------------------------ -->
<br><br>
<input type="submit" name="submit" value="Post comment"><br><br>
</form>
</body>
</html>
And the received part - received.php
<?php
//////////////////////////////////////////Check Capch Function Start
function CapchaCheck()
{
$captcha;
if(isset($_POST['g-recaptcha-response']))
{
$captcha=$_POST['g-recaptcha-response'];
}
if(!$captcha)
{
return false;
}
$secreatKey="6LdLqv8SAAAAAIWxKcn2zIKjWau2Mdz6yzE3Kkcm";
$response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secreatKey."&response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']);
var_dump($response);
if($response.success==false)
{
return false;
}
else
{
return true;
}
}
//////////////////////////////////////////Check ReCaptcha Function End
if(CapchaCheck())
{
echo '<h2>Thanks for posting comment.</h2>';
}
else
{
echo '<h2>You are spammer ! Get the @$%K out</h2>';
}
?>
It works perfectly.
But I don't want to check if ReCapcha is correct after it is submitted. I want to prevent the users to submit if the ReCaptcha is wrong.
So, I think I need jQuery for this.
But I don't know how to implement it.
Can anyone help me please.
Thanks in advance for helping.