Captcha Always Is Invalid When Testlimit=1

This is my captcha setting




   			'captcha'=>array(

   			'class'=>'CCaptchaAction',

   			'backColor'=>0xFFFFFF,

   			'foreColor'=>0xFF712E,

   			'offset'=>-3,

   			'height'=>45,

   			'testLimit'=>1,

			),



In this case Captcha entered always is invalid, but when testLimit set to more than 1, it work’s correctly. what’s the problem ???

Ajax and Client Validation is disabled.

EDIT: Captcha works on Contact form without any problem !!!

register.php (form)




<div class="form wide">


<?php $form=$this->beginWidget('CActiveForm', array(

	'id'=>'register-form',

)); ?>


	<div class="row">

		<?php echo $form->label($model,'username'); ?>

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

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

	</div>


	<div class="row">

		<?php echo $form->label($model,'email'); ?>

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

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

	</div>


	<div class="row">

		<?php echo $form->label($model,'password'); ?>

		<?php echo $form->passwordField($model,'password'); ?>

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

	</div>


	<div class="row">

		<?php echo $form->label($model,'password_confirm'); ?>

		<?php echo $form->passwordField($model,'password_confirm'); ?>

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

	</div>


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

	<div class="row">

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

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

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


    	<div class="captcha">

    	<?php $this->widget('CCaptcha',array(

        	'buttonLabel'=>Yii::t('form','Get new code'),

        	//'clickableImage'=>true,

        	'imageOptions'=>array('class'=>'image'),

        	'buttonOptions'=>array('class'=>'button'),

    	)); ?>

    	</div>

	</div>


	<?php endif; ?>


	<div class="row buttons">

		<?php echo CHtml::submitButton(Yii::t('form','Submit')); ?>

	</div>


<?php $this->endWidget(); ?>


</div><!-- form -->



[b]Contact.php /b:




<?php if(Yii::app()->user->hasFlash('contact')): ?>


<div class="flash-success">

	<?php echo Yii::app()->user->getFlash('contact'); ?>

</div>


<?php else: ?>


<div class="form wide">


	<?php $form=$this->beginWidget('CActiveForm', array(

	'id'=>'contact-form',

)); ?>


	<div class="row">

    	<?php echo $form->label($model,'name'); ?>

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

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

	</div>


	<div class="row">

    	<?php echo $form->label($model,'email'); ?>

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

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

	</div>


	<div class="row">

    	<?php echo $form->label($model,'subject'); ?>

    	<?php echo $form->textField($model,'subject',array('size'=>60,'maxlength'=>128)); ?>

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

	</div>


	<div class="row">

    	<?php echo $form->label($model,'body'); ?>

    	<?php echo $form->textArea($model,'body',array('rows'=>6, 'cols'=>50)); ?>

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

	</div>


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

	<div class="row">

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

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

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


    	<div class="captcha">

    	<?php $this->widget('CCaptcha',array(

        	'buttonLabel'=>Yii::t('form','Get new code'),

        	//'clickableImage'=>true,

        	'imageOptions'=>array('class'=>'image'),

        	'buttonOptions'=>array('class'=>'button'),

    	)); ?>

    	</div>

	</div>


	<?php endif; ?>


	<div class="row buttons">

    	<?php echo CHtml::submitButton('Submit'); ?>

	</div>


	<?php $this->endWidget(); ?>


</div><!-- form -->


<?php endif; ?>



Controller/actionSignup:




	public function actionSignup()

	{

    	$model = new NewUser('register');

    	if(isset($_POST['NewUser']))

    	{

        	$model->attributes = $_POST['NewUser'];

        	if($model->validate())

            	if($model->save()){

                	$url = Yii::app()->createAbsoluteUrl('site/verify',array(

                    	'type'=>'user', 'verifyString'=>$model->verify_string));

                	send_verify_code($url,null,$model->email);

                	$this->render('notify',array('status'=>'registered'));

                	Yii::app()->end();

            	}

    	}

    	$this->render('register',array('model'=>$model));

	}



Controller/actionContact:




	public function actionContact()

	{

		$model=new ContactForm;

		if(isset($_POST['ContactForm']))

		{

			$model->attributes=$_POST['ContactForm'];

			if($model->validate())

			{

				$name='=?UTF-8?B?'.base64_encode($model->name).'?=';

				$subject='=?UTF-8?B?'.base64_encode($model->subject).'?=';

				$headers="From: $name <{$model->email}>\r\n".

					"Reply-To: {$model->email}\r\n".

					"MIME-Version: 1.0\r\n".

					"Content-type: text/plain; charset=UTF-8";


				mail(Yii::app()->params['adminEmail'],$subject,$model->body,$headers);

				Yii::app()->user->setFlash('contact','Thank you for contacting us. We will respond to you as soon as possible.');

				$this->refresh();

			}

		}

		$this->render('contact',array('model'=>$model));

	}



NewUser Model->rules:




	public function rules()

	{

		// NOTE: you should only define rules for those attributes that

		// will receive user inputs.

		return array(

			array('username, email, password', 'required'),

			array('username', 'length', 'min'=>3,'max'=>50),

			array('username', 'verifyUser'),

			array('email', 'length', 'max'=>255),

			array('email', 'email'),

			array('email', 'verifyEmail'),

			array('password', 'length', 'min'=>4, 'max'=>60, 'allowEmpty'=>false),

        	array('password', 'compare', 'compareAttribute'=>'password_confirm', 'on'=>'register'),

        	array('password_confirm','safe', 'on'=>'register'),


        	// verifyCode needs to be entered correctly

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

			// The following rule is used by search().

			// Please remove those attributes that should not be searched.

			array('id, username, email, password, verify_string', 'safe', 'on'=>'search'),

		);

	}



Contact Model->rules:




	public function rules()

	{

		return array(

			// name, email, subject and body are required

			array('name, email, subject, body', 'required'),

			// email has to be a valid email address

			array('email', 'email'),

			// verifyCode needs to be entered correctly

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

		);

	}



[url=&quot;http://www.yiiframework.com/forum/index.php/topic/20087-captcha-validator-dont-work-properly/&quot;]Related topic

[/url]

i think you can pass the unique_id on captcha (register.php)


 $unique_id = rand(0, 999999);





<?php $this->widget('CCaptcha',array(

                'buttonLabel'=>Yii::t('form','Get new code'),

                //'clickableImage'=>true,

                'imageOptions'=>array('class'=>'image'),

                'buttonOptions'=>array('class'=>'button'),

                'id' => $unique_id

        )); ?>



I don’t try your way, because the problem is this.