Prestashop - AuthController.php未收到输入值

时间:2016-05-11 06:38:54

标签: php prestashop recaptcha

我试图将google reCaptcha添加到prestashop的opc注册页面,我有复选框设置并且它正在运行但是php文件没有收到验证码响应。让我解释。这是我到目前为止所做的:在我的header.tpl中,我添加了

<script src='https://www.google.com/recaptcha/api.js'></script>

在order-opc-new-account.tpl中,我添加了

<div class="g-recaptcha" data-sitekey="[my_public_key]"></div>

在我的AuthController.php中,我添加了

if (Tools::isSubmit('submitAccount') OR Tools::isSubmit('submitGuestAccount')) //if statement was already present
{   
    // captcha code I added
    $reCaptchaUrl='https://www.google.com/recaptcha/api/siteverify';
    $reCaptchaSecret = '[my_secret_key]';
    $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 = new FileLogger(0);
        $logger->setFilename(_PS_ROOT_DIR_."/log/debug.log");
        $logger->logDebug("Captcha failed: ".$reCaptchaResponse);
    }

    // ... prestashop registration code
}

我通过调试消息了解到$reCaptchaResponse变量实际上每次都是空的,即使已经检查过验证码。有什么想法吗?

修改:表单实际上将数据发送到authentication.php,其中包含以下行

require(dirname(__FILE__).'/config/config.inc.php');
ControllerFactory::getController('AuthController')->run();

我的猜测是,这段代码将表单数据转发AuthController.php,但它只转发已被告知要转发的字段。它无法识别新的重新访问字段,也不会将该数据转发到文件中。所以我需要找到谁来决定转发哪些数据。

1 个答案:

答案 0 :(得分:2)

确保<%= select_tag :db_field, options_for_select(@users.select([:email, 'users.id']).map{|user| [user.email, user.id]}), class: 'class_name_1 class_name_2', style: "min-width: 100px;" %> 位于FORM元素中。