【问题标题】:Weird captcha in Yii popupYii 弹出窗口中奇怪的验证码
【发布时间】:2012-06-16 09:47:14
【问题描述】:

我在 YII 项目中遇到了验证码问题。我在弹出表单中包含了一个验证码。它显示正确,但验证存在问题。验证有时是正确的,如果我们第一次尝试输入正确的单词,验证说它是错误的,在生成另一个代码后验证成功。为什么?

在模型-> 规则中:

array('verifyCode', 'captcha', 'allowEmpty'=>!CCaptcha::checkRequirements(),'on'=> 'signup')

在控制器中 -> 通过 renderPartial 调用注册表单

$this->renderPartial('signUp',array('model'=>$model),false,true);

在视图中:

<?php $form=$this->beginWidget('CActiveForm', array(
    'id'=>'sign-up-form',
    'enableAjaxValidation'=>true,
    'enableClientValidation'=>true,
    'clientOptions'=>array(
        'validateOnSubmit'=>true,
    ),
)); ?>

-----------------------
-----------------------

<?php if(CCaptcha::checkRequirements()): ?>                             
    <?php echo $form->labelEx($model, 'verifyCode', array('for'=>'User_security_code')); ?>
    <?php $this->widget('CCaptcha'); ?>     
    <?php echo $form->textField($model,'verifyCode',array('class'=>'txt-style width-289')); ?>
    Please enter the letters as they are shown in the image above. Letters are not case-sensitive.
    <?php echo $form->error($model,'verifyCode',array('class'=>'error_msg')); ?>
 <?php endif; ?>    

【问题讨论】:

    标签: php jquery yii


    【解决方案1】:

    我在视图中添加了这个

    <?php
    Yii::app()->clientScript->registerScript(
            'initCaptcha',
            '$("#yw0_button").trigger("click");',
            CClientScript::POS_READY);
    ?>
    

    `CCaptchaAction.php` updated `$testLimit = 0;` //for unlimted test`
    

    问题解决了。我不确定这是不是正确的方法,但对于我目前的情况,它有所帮助。

    【讨论】:

      猜你喜欢
      • 2017-03-20
      • 1970-01-01
      • 1970-01-01
      • 2014-06-23
      • 2011-02-05
      • 2015-01-12
      • 1970-01-01
      • 2020-09-16
      • 1970-01-01
      相关资源
      最近更新 更多