Jump to content

Adding ReCaptcha to OPC Registration Form


Recommended Posts

I'm trying to add Google's reCaptcha to my new user registration form on one page checkout page. I've got the widget appearing on the page and it works fine after my testing. But right now it has nothing to do with the form because I haven't done any server side validation yet.

 

That's because I have no clue which page handles the data once user clicks on the Submit/Save button on the page. Can anyone point me to the right direction?

 

PS. I found this link about adding reCaptcha on contact form but don't know how to do it on the registration page. Any help would be greatly appreciated. Thanks

 

Edit: The HTML form that appears on the OPC page is in file themes/{themes-coton}/order-opc-new-account.tpl and in that the account creation form has no action defined 

<form action="#" method="post" id="new_account_form" class="std">

I can't seem to understand how the registration works.

Edited by Vee.K727 (see edit history)
Link to comment
Share on other sites

  • 2 weeks later...

I have some progress on it. I found the code that takes care of the registration. It's in AuthController.php in

if (Tools::isSubmit('submitAccount') OR Tools::isSubmit('submitGuestAccount')){
   //registration code
}

I added the following lines for reCaptcha

if (Tools::isSubmit('submitAccount') OR Tools::isSubmit('submitGuestAccount')) {

$reCaptchaUrl='https://www.google.com/recaptcha/api/siteverify';
$reCaptchaSecret = 'mysecretkey';
$reCaptchaResponse = $_POST['g-recaptcha-response'];
$ip = $_SERVER['REMOTE_ADDR'];

$verifyCaptcha = file_get_contents($reCaptchaUrl."?secret=".$reCaptchaSecret."&response=".$reCaptchaResponse."&remoteip=".$ip);
$captchaReply = json_decode($verifyCaptcha);

if(isset($captchaReply->success) AND $captchaReply->success == true){
   $logger = new FileLogger(0);
   $logger->setFilename(_PS_ROOT_DIR_."/log/debug.log");
   $logger->logDebug("Captcha was successful: ".$reCaptchaResponse);
} else {
   //captcha failed
   $logger->logDebug("Captcha failed: ".$reCaptchaResponse);
}
}

I've learned that AuthController is not receiving any values from the captcha even when it's checked off. the variable $reCaptchaResponse is empty. Any ideas why?

 

 

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...