Zend framework Zend框架和ReCaptcha

Zend framework Zend框架和ReCaptcha,zend-framework,recaptcha,Zend Framework,Recaptcha,我需要在ZF应用程序的表单中插入ReCaptcha。我试图遵循官方文档,但ReCaptcha服务总是返回错误“不正确的captcha sol”。 我正在使用的代码: (在表格中) (在控制器中) 有什么帮助吗?为什么要从表单中提取单独的元素进行检查?我就是这样做的: 表格 // configure the captcha service $privateKey = 'XXXXXXXXXXXXXXXXXXX'; $publicKey = 'YYYYYYYYYYYYYYYYYYYY'; $recap

我需要在ZF应用程序的表单中插入ReCaptcha。我试图遵循官方文档,但ReCaptcha服务总是返回错误“不正确的captcha sol”。 我正在使用的代码:

(在表格中)

(在控制器中)


有什么帮助吗?

为什么要从表单中提取单独的元素进行检查?我就是这样做的:

表格

// configure the captcha service
$privateKey = 'XXXXXXXXXXXXXXXXXXX';
$publicKey = 'YYYYYYYYYYYYYYYYYYYY';
$recaptcha = new Zend_Service_ReCaptcha($publicKey, $privateKey);

// create the captcha control
$captcha = new Zend_Form_Element_Captcha('captcha',
                                array('captcha' => 'ReCaptcha',
                                      'captchaOptions' => array(
                                          'captcha' => 'ReCaptcha',
                                          'service' => $recaptcha)));

$this->addElement($captcha);
<?php
class Default_Form_ReCaptcha extends Zend_Form
{
    public function init()
    {
        $publickey = 'YOUR KEY HERE';
        $privatekey = 'YOUR KEY HERE';
        $recaptcha = new Zend_Service_ReCaptcha($publickey, $privatekey);

        $captcha = new Zend_Form_Element_Captcha('captcha',
            array(
                'captcha'       => 'ReCaptcha',
                'captchaOptions' => array('captcha' => 'ReCaptcha', 'service' => $recaptcha),
                'ignore' => true
                )
        );

        $this->addElement($captcha);

        $this->addElement('text', 'data', array('label' => 'Some data'));
        $this->addElement('submit', 'submit', array('label' => 'Submit'));
   }
}
查看

echo $this->form;
这是非常透明的代码。当执行表单的isValid()时,它将验证其所有元素,并且仅当每个元素都有效时才返回true

当然,要确保您使用的密钥与运行此代码的域相关


如果您有更多问题,请告诉我。

我正在关注的是快速入门,对我来说,以下是对“Figlet”验证码的更快更改

   $this->addElement('captcha', 'captcha', array(
        'label' => 'Please enter two words displayed below:',
        'required' => true,
        'captcha' => array(
            'pubkey' => '---your public key here---',
            'privkey' => '---your private key here---',
            'captcha' => 'reCaptcha'
        )
    ));

这应该是公认的答案。我用过它,它工作得很好。最简单的方法是重新获取TCHA。谢谢你,伙计;)
echo $this->form;
   $this->addElement('captcha', 'captcha', array(
        'label' => 'Please enter two words displayed below:',
        'required' => true,
        'captcha' => array(
            'pubkey' => '---your public key here---',
            'privkey' => '---your private key here---',
            'captcha' => 'reCaptcha'
        )
    ));