Re: Support Thread for Google reCAPTCHA plugin
Try this one:
PHP Code:
<?php
/**
*
* @package plugins
* @copyright Copyright 2003-2012 Zen Cart Development Team
* @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
*
* Designed for v1.5.4
* Observer class for Google reCaptcha
*/
class google_recaptcha extends base {
/**
* @var array
*/
private $pages_to_checkcheck = array();
function __construct() {
//comment out any pages you do NOT want to check
$pages_to_check[] = 'NOTIFY_CONTACT_US_CAPTCHA_CHECK';
$pages_to_check[] = 'NOTIFY_CREATE_ACCOUNT_CAPTCHA_CHECK';
//$pages_to_check[] = 'NOTIFY_REVIEWS_WRITE_CAPTCHA_CHECK';
$pages_to_check[] = 'NOTIFY_FAQ_CAPTCHA_CHECK';
$pages_to_check[] = 'NOTIFY_FAQ_PAGE_CAPTCHA_CHECK';
$this->attach($this,$pages_to_check);
}
function update(&$class, $eventID, $paramsArray = array()) {
global $messageStack, $error, $privatekey;
require_once __DIR__ . '/google/autoload.php';
$recaptcha = new \ReCaptcha\ReCaptcha($privatekey);
// If file_get_contents() is locked down on your PHP installation to disallow
// its use with URLs, then you can use the alternative request method instead.
// This makes use of fsockopen() instead.
//$recaptcha = new \ReCaptcha\ReCaptcha($privatekey, new \ReCaptcha\RequestMethod\SocketPost());
// This makes use of curl instead
//$recaptcha = new \ReCaptcha\ReCaptcha($privatekey, new \ReCaptcha\RequestMethod\Curl());
$resp = $recaptcha->verify($_POST['g-recaptcha-response'], $_SERVER['REMOTE_ADDR']);
if (!$resp->isSuccess()) {
$event_array = array('NOTIFY_CONTACT_US_CAPTCHA_CHECK' => 'contact', 'NOTIFY_CREATE_ACCOUNT_CAPTCHA_CHECK' => 'create_account', 'NOTIFY_REVIEWS_WRITE_CAPTCHA_CHECK' => 'review_text', 'NOTIFY_FAQ_CAPTCHA_CHECK' => 'faq', 'NOTIFY_FAQ_PAGE_CAPTCHA_CHECK' => 'faq_page');
$messageStack->add($event_array[$eventID], $resp->getErrors());
$messageStack->add('faq', GOOGLE_RECAPTCHA_CHECK_ERROR);
$messageStack->add('faq_page', GOOGLE_RECAPTCHA_CHECK_ERROR);
$error = true;
}
return $error;
}
}
Re: Support Thread for Google reCAPTCHA plugin
Nope again.... This one is definately different, I think it is because it is a ajax loaded form on the product info page (and setting the mesage stack page to product info does not work, tried it.).
Take a look at it HERE, click on the Ask a Question link.
Re: Support Thread for Google reCAPTCHA plugin
Ok so the popup displays the following if not checked:
"Please fill in the required information and submit it again. Thank you."
So I would suggest finding where that message is coded, then whatever file that is you should be able to add an additional messageStack to it for the reCAPTCHA.
Re: Support Thread for Google reCAPTCHA plugin
Quote:
Originally Posted by
marcopolo
Ok so the popup displays the following if not checked:
"Please fill in the required information and submit it again. Thank you."
So I would suggest finding where that message is coded, then whatever file that is you should be able to add an additional messageStack to it for the reCAPTCHA.
That error message is handled in the class.faq_request.php file with the following line"
PHP Code:
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
echo json_encode(array('status' => 'error', 'message' => 'Please fill in the required information and submit it again. Thank you.'));
} else {
$messageStack->add_session('product_info', 'Please fill in all information and try again!', 'warning');
zen_redirect(zen_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . (int)$_GET['products_id']));
}
I attempted to add this using that format
PHP Code:
//bof google recaptcha
if (!$resp->is_valid) {
$error = true;
echo json_encode(array('status' => 'error', 'message' => 'Please confirm you are not a robot.'));
exit();
} //eof google recaptcha
When I did that this error message shows up regardless of if you check the recaptcha.
I also tried
PHP Code:
//bof google recaptcha
$resp = $recaptcha->verify($_POST['g-recaptcha-response'], $_SERVER['REMOTE_ADDR']);
if (!$resp->is_valid) {
$error = true;
echo json_encode(array('status' => 'error', 'message' => 'Please confirm you are not a robot.'));
exit();
} //eof google recaptcha
This does nothing when you click the send button regardless of if you check the recaptcha. (it actually gives a 500 internal server error)
I'm thinking that the issue is actually in the way it is checking the recaptcha and that it thinks the recaptcha is empty no matter what.
I think the reason that it is working the way it is now is because the ajax form sees the recaptcha as a field, if that field is empty it returns 'Please fill in the required information and submit it again. Thank you.', if ALL of the fields have "something" then it returns 'We have received your question. We will respond to you as quickly as possible. Thank you for asking.' and sends the message.
Re: Support Thread for Google reCAPTCHA plugin
can you post the whole contents of class.faq_request.php
1 Attachment(s)
Re: Support Thread for Google reCAPTCHA plugin
Quote:
Originally Posted by
marcopolo
can you post the whole contents of class.faq_request.php
Here is my current file and the one included with the ajax FAQ mod
Attachment 15743
Re: Support Thread for Google reCAPTCHA plugin
Ok try the following, edit your file and add:
PHP Code:
if ($error == true) {
echo json_encode(array('status' => 'error', 'message' => 'Please confirm you are not a robot'));
exit();
}
below line:
PHP Code:
if(isset($_POST['email_address']) && !empty($_POST['email_address']) && isset($_POST['fullname']) && !empty($_POST['fullname']) && isset($_POST['message']) && !empty($_POST['message']) && $error==false) {
should look like:
PHP Code:
if(isset($_POST['email_address']) && !empty($_POST['email_address']) && isset($_POST['fullname']) && !empty($_POST['fullname']) && isset($_POST['message']) && !empty($_POST['message']) && $error==false) {
if ($error == true) {
echo json_encode(array('status' => 'error', 'message' => 'Please confirm you are not a robot'));
exit();
}
Re: Support Thread for Google reCAPTCHA plugin
So this did NOT work:
PHP Code:
if(isset($_POST['email_address']) && !empty($_POST['email_address']) && isset($_POST['fullname']) && !empty($_POST['fullname']) && isset($_POST['message']) && !empty($_POST['message']) && $error==false) {
if ($error == true) {
echo json_encode(array('status' => 'error', 'message' => 'Please confirm you are not a robot'));
exit();
}
It is checking if $error == true after it has already confirmed $error == false.
But this did work!
PHP Code:
//bof google recaptcha check
if ($error == true) {
echo json_encode(array('status' => 'error', 'message' => 'Please confirm you are not a robot.'));
exit();
}
//eof google recaptcha check
if(isset($_POST['email_address']) && !empty($_POST['email_address']) && isset($_POST['fullname']) && !empty($_POST['fullname']) && isset($_POST['message']) && !empty($_POST['message']) && $error==false) {
Thanks for getting me headed in the right direction.
Re: Support Thread for Google reCAPTCHA plugin
Re: Support Thread for Google reCAPTCHA plugin
Hello,
I don't know if I am at the right place here but i haven's seen a "start thread" option. Here's
my problem.
reCAPTCHA is n't working all the time i haven't seen it on the new account page and not
always on the contact us page. i checked the files they are all there in the right place, checked
google key's they are also in the right file?
So what can be wrong in my situation ? (check itparts.biz/zentest)