Yii Captcha Does Not Work First Time

I am trying to create register form where I used captcha. I have enabled ejax validation. But the there is a problem, captcha does not work first time. When I generate new captcha code, that works. My code is:

In model,




public $verifyCode;


public function rules()

{

return array(

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


    array('id, first_name,last_name, email, username, password, password_repeat, user_type,  keystring, status, logo_url, last_login_time, create_time, update_time, validation', 'safe', 'on'=>'search'),

    );

}



In controller:




public function actions()

{

    return array(

        'captcha'=>array(

            'class'=>'CCaptchaAction',

            'backColor'=>0xFFFFFF,

            'testLimit'=>3,

        ),

    );

}



In view:




<?php if(CCaptcha::checkRequirements()): ?>

<div class="row">

    <?php echo $form->labelEx($model,'verifyCode'); ?>

    <?php $this->widget('CCaptcha', array('captchaAction'=>'user/captcha')); ?>

</div>

<div class="formfieldarea">

    <div class="form-text"></div>

    <div class="form-field">

        <?php echo $form->textField($model,'verifyCode'); ?>

        <div class="hint">Please enter the letters as shown.

            <br/>Letters are not case-sensitive.</div>

        <?php echo $form->error($model,'verifyCode'); ?>

    </div>

</div>

<?php endif; ?>



I have searched in google a lot to find the solution. But did not find. Please help someone.

Hi StreetCoder,

You may want to read these threads:

http://www.yiiframework.com/forum/index.php/topic/16405-captcha-is-not-working-first-time

http://www.yiiframework.com/forum/index.php?/topic/11425-

And the documentation for CActiveForm:

http://www.yiiframework.com/doc/api/1.1/CActiveForm