2

我正在尝试在 cakephp中实现 fun-captcha( http://codecanyon.net/item/fun-captcha/163632 )。

$this->CaptchaGenerator = new CaptchaGenerator();
$this->set('captcha0', $this->CaptchaGenerator->renderCaptcha(0));
$this->set('captcha1', $this->CaptchaGenerator->renderCaptcha(1));
$this->set('captcha2', $this->CaptchaGenerator->renderCaptcha(2));
if ($this->request->is('post')):
    $captchaArray['captcha0flag'] = @$this->request->data['captcha0flag'];
    $captchaArray['captcha1flag'] = @$this->request->data['captcha1flag'];
    $captchaArray['captcha2flag'] = @$this->request->data['captcha2flag'];
    for ($i = 0; $i < count($captchaArray); $i++) {
        $responseValue[] = $this->CaptchaGenerator->checkCaptcha($captchaArray, $i);
    }
    pr($responseValue);

在 pr($responseValue) 我得到这个结果

数组( [0] => 1 [1] => 1 [2] => 1 )

这意味着来自 3 个盒子的值是真实的。然后,如果此值为真,我将尝试使用此代码保存我的帖子和标签

if ($responseValue == 1) {
    if (isset($temp)) {
        $this->Tag->saveMany($temp);
    }
    $listOfId = $this->Tag->tagIdArray;
    $this->request->data['Claim']['Tag'] = $listOfId;
    $this->Claim->save($this->request->data);
    $this->redirect('/');
}
else {
    $this->Session->setFlash('Nop', 'flash', array('alert' => 'error'));
    $this->redirect('/start-claim');
}

但是仍然不能提交我显示的 Flash 消息“NOP”的帖子。任何人都可以建议我吗????

4

1 回答 1

0

首先,在您不再需要它们时取消设置值,并且您将 $responseArray 的值作为数组获取,因此 $responseArray == 1 使用以下代码,我相信它会对您有所帮助:)

在您不再需要数据后立即取消设置数据

if($responseValue[0] && $responseValue[1] && $responseValue[2] == 1) {
                ........
            }
            else {
                ..........
            }
            unset($this->request->data['captcha0flag']);
            unset($this->request->data['captcha1flag']);
            unset($this->request->data['captcha2flag']);

快乐的编码:)

于 2013-08-24T10:32:22.683 回答