function hcaptcha_captcha_validation in hCaptcha 7
Same name and namespace in other branches
- 8 hcaptcha.module \hcaptcha_captcha_validation()
CAPTCHA Callback; Validates the hCaptcha code.
1 string reference to 'hcaptcha_captcha_validation'
- hcaptcha_captcha in ./
hcaptcha.module - Implements hook_captcha().
File
- ./
hcaptcha.module, line 95
Code
function hcaptcha_captcha_validation($solution, $response, $element, $form_state) {
$hcaptcha_site_key = variable_get('hcaptcha_site_key', '');
$hcaptcha_secret_key = variable_get('hcaptcha_secret_key', '');
if (!isset($_POST['h-captcha-response']) || empty($_POST['h-captcha-response']) || empty($hcaptcha_secret_key)) {
return false;
}
$captcha = new HCaptcha($hcaptcha_site_key, $hcaptcha_secret_key, array(), new Drupal7Post());
$captcha
->validate($_POST['h-captcha-response'], ip_address());
if ($captcha
->isSuccess()) {
// Verified!
return true;
}
else {
foreach ($captcha
->getErrors() as $error) {
watchdog('hCaptcha', '@error', array(
'@error' => $error,
), WATCHDOG_ERROR);
}
}
return false;
}