首页 文章

yii博客验证码永远不会验证

提问于
浏览
0

我试图将验证码与Yii博客(http://www.yiiframework.com/doc/blog/)集成,以便用户必须在评论表中填写验证码 . 在我添加的评论表单视图中

<?php if(CCaptcha::checkRequirements()): ?>
    <div class="row">
            <?php echo $form->labelEx($model,'verifyCode'); ?>
            <div>
            <?php $this->widget('CCaptcha', array('captchaAction'=>'comment/captcha')); ?>
            <?php echo $form->textField($model,'verifyCode'); ?>
            </div>
            <div class="hint">Please enter the letters as they are shown in the image above.
            
Letters are not case-sensitive.</div> <?php echo $form->error($model,'verifyCode'); ?> </div> <?php endif; ?>

我已将此数组添加到comment控制器中的accessRules():

array('allow',  // allow all users to perform 'index' and 'view' actions
                    'actions'=>array('index','view', 'captcha'),
                    'users'=>array('*'),
            ),

我在CommentController中覆盖actions():

public function actions()
{
    return array(
        // captcha action renders the CAPTCHA image displayed on the contact page
        'captcha'=>array(
            'class'=>'CCaptchaAction',
            'backColor'=>0xD99D25,
        ),
    );
}

在评论模型中,我添加了一条新规则:

array('verifyCode', 'captcha', 'on' => 'insert', 'allowEmpty'=>!Yii::app()->user->isGuest)

和新的公共成员:

public $verifyCode;

因为评论表单是从博客actionView()显示的,所以我认为它会产生问题 . 验证码显示但从不验证 . 有任何想法吗?

1 回答

  • 0

    您还需要将captchaAction添加到Comment模型验证规则中,如下所示:

    array('verifyCode', 'captcha', 'on' => 'insert', 'allowEmpty'=>!Yii::app()->user->isGuest, 'captchaAction'=>'comment/captcha')
    

相关问题