dongqindan4406 2012-06-16 09:47
浏览 99
已采纳

Yii popup中的奇怪验证码

I have a problem with captcha in my YII project. I included a captcha in popup form. It's showing correctly, but there's a problem with the validation. The validation is true sometimes, if we entered the correct word in first attempt, the validation says it is wrong, after generating another code the validation succeeds. Why?

In model-> rules:

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

In controller -> calling the signup form via renderPartial

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

In view :

<?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; ?>    
  • 写回答

1条回答 默认 最新

  • duanmei1930 2012-06-18 05:52
    关注

    i added this in view

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

    and in

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

    and the problem solved. I'm not sure about this is the right way, but for my current scenario it helped.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度