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(








In view:

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

<div class="row">

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

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


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



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



And the documentation for CActiveForm: