-
-
Save IngoWinter/1641046cba3818b56aae2008767e7b9d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class rex_xform_iw_recaptcha extends rex_xform_abstract | |
{ | |
function enterObject() | |
{ | |
$output = '<script src="https://www.google.com/recaptcha/api.js" async defer></script>'; | |
$output .= '<div class="g-recaptcha" data-sitekey="'.$this->getElement(1).'"></div>'; | |
$this->params['form_output'][$this->getId()] = $output; | |
} | |
function getDescription() | |
{ | |
return 'iw_recaptcha -> iw_recaptcha|site_key'; | |
} | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class rex_xform_validate_iw_recaptcha extends rex_xform_validate_abstract | |
{ | |
function enterObject() | |
{ | |
if ($this->params["send"] == "1") | |
{ | |
if (isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])) | |
{ | |
$secret = $this->getElement(2); | |
$verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret=' . $secret . '&response=' . $_POST['g-recaptcha-response']); | |
$responseData = json_decode($verifyResponse); | |
if (!$responseData->success) | |
{ | |
$this->params["form_show"] = TRUE; | |
$this->params["hasWarnings"] = TRUE; | |
$this->params["warning_messages"][] = $this->getElement(3); | |
} | |
} | |
else | |
{ | |
$this->params["form_show"] = TRUE; | |
$this->params["hasWarnings"] = TRUE; | |
$this->params["warning_messages"][] = $this->getElement(4); | |
} | |
} | |
} | |
function getDescription() | |
{ | |
return "validate|iw_recaptcha|secret_key|recaptcha_wrong|recaptcha_empty"; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment