Bug Captcha


(Xicond) #1

Captcha buggy while the testLimit 1 and run :

if($model->validate() && $model->save()){

$message = "Terima kasih atas kiriman info Resto/Rumah Makan Anda, Kami akan mengklarifikasi kembali.";

}

it seems that the validator, didn’t cache the valid captcha and, directly invalidate the last one on the validate functional


(Maurizio Domba Cerin) #2

Note that with your code

[color="#1C2837"][size="2"]


$model->validate() && $model->save()

[/size][/color]

[color="#1C2837"] [/color][color="#1C2837"][size="2"]the validation is done 2 times![/size][/color]

[color="#1C2837"] [/color]

[color="#1C2837"] [/color]


(Xicond) #3

Yes, but on my idealistic, whatever condition I run on mycode, it shouldn’t impact for invalidation the captcha, the captcha should only invalidate on user attempt…

is any best way to reach it?


(Maurizio Domba Cerin) #4

Did you try with just $model->save() ?

makes no sense to do the validation 2 consecutive times.


(Xicond) #5

Yes, that’s the only solution, somehow, I need to make a test validate before do a save action,

that’s upper sample just a short example, not the real code.

if on same action there’s 1 var name branching conditional to two kind of model, one is modelform, the other is cactiverecord,

  • so in the modelform object type, I can do validate and call save method own created,

  • but on other flow come in the cactiverecord, it getting error


(Maurizio Domba Cerin) #6

Well if you need to validate before the save… then you can use $model->save(false) so that the second time validation is not performed…


(Arunvivekmail) #7

To make the capctha you have to do :

Add the code rules to your controller id. For example UserController.

public function actions(){

return array(

// captcha action renders the CAPTCHA image displayed on the user registration page


'captcha'=>array(


  'class'=>'CCaptchaAction',


  'backColor'=>0xFFFFFF,


),

);

}

The view form should like this

$form=$this->beginWidget(‘CActiveForm’,array(

‘id’=>‘user-form’,

‘enableAjaxValidation’=>false,

));

?>

Don’t forget to put the access rules like this :

array('allow', // allow authenticated user to perform 'create' and 'update' actions


  'actions'=>array('create','update','captcha'),


  'users'=>array('@'),


),

Add field in your model for example User.php

public $verifyCode;

Add this code to your view form

<?php if(extension_loaded(‘gd’)): ?>

<div class="row">

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

<div>

<?php $this->widget(‘CCaptcha’); ?>

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

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

</div>

</div>

<?php endif ?>

The last add the rules here in the rules() model

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

i think this will help beginers…i tried,i got