Skip to content

Instantly share code, notes, and snippets.

@ircykk
Created March 14, 2018 15:51
Show Gist options
  • Save ircykk/16d8022029e1aadb56a649fa26d59e3e to your computer and use it in GitHub Desktop.
Save ircykk/16d8022029e1aadb56a649fa26d59e3e to your computer and use it in GitHub Desktop.
Simple reCAPTCHA PrestaShop contact form controller override
<?php
class ContactController extends ContactControllerCore
{
public function postProcess()
{
if (Tools::isSubmit('submitMessage')) {
$response = $_POST["g-recaptcha-response"];
$url = 'https://www.google.com/recaptcha/api/siteverify';
$data = array(
'secret' => '_YOUR_SECRET_',
'response' => $_POST["g-recaptcha-response"]
);
$options = array(
'http' => array (
'method' => 'POST',
'content' => http_build_query($data)
)
);
$context = stream_context_create($options);
$verify = file_get_contents($url, false, $context);
$captcha_success=json_decode($verify);
if ($captcha_success->success==false) {
$this->errors[] = Tools::displayError('Captcha error.');
} else {
return parent::postProcess();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment