How to install Google reCHAPTCHAv2 on the form?
Hi,
I’m having a hard time to install Google’s reCAPTCHA V2 on my form page I made with UE. On front end first 2-steps (java script pasting within header, adding a line with the public key) were all done. The problem is the last one; server side setting.
I can't write codes so I searched for something useful and found this.
Do you think this can be used as a part of form I made with UE?
<?php
// Checks if form has been submitted
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
function post_captcha($user_response) {
$fields_string = '';
$fields = array(
'secret' => 'secret-kkkkkkkeeeeeeeyyyyy',
'response' => $user_response
);
foreach($fields as $key=>$value)
$fields_string .= $key . '=' . $value . '&';
$fields_string = rtrim($fields_string, '&');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.google.com/recaptcha/api/siteverify');
curl_setopt($ch, CURLOPT_POST, count($fields));
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, True);
$result = curl_exec($ch);
curl_close($ch);
return json_decode($result, true);
}
// Call the function post_captcha
$res = post_captcha($_POST['g-recaptcha-response']);
if (!$res['success']) {
// What happens when the CAPTCHA wasn't checked
echo '<p>Please go back and make sure you check the security CAPTCHA box.</p><br>';
} else {
// If CAPTCHA is successfully completed...
// Paste mail function or whatever else you want to happen here!
echo '<br><p>CAPTCHA was completed successfully!</p><br>';
}
} else { ?>
I am wondering if I can just paste what UE generates to send email where it says “ // Paste mail function or whatever else you want to happen here!” But I guess it’s not that simple…
I read Google’s documents about this but I know too little to understand.
Any help will be appreciated :-)
I attached the form file and UE file.
Thank you so much for your help,
Rika