2012-06-16 36 views
0

我在我的YII項目中遇到了驗證碼問題。我以彈出窗體的形式包含了驗證碼。它顯示正確,但驗證有問題。驗證是有時候,如果我們在第一次嘗試中輸入了正確的單詞,那麼驗證認爲它是錯誤的,在生成驗證成功的另一個代碼之後。爲什麼?Yii的奇怪驗證碼popup

在模型 - >規則:

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; ?>  

回答

0

我加入有鑑於此

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

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

,並解決了這個問題。我不確定這是否是正確的方式,但對於我目前的情況來說,這有幫助。