Reputation: 8394
User model:
public function rules()
{
return array(
...
array('verifyCode', 'captcha', 'on'=>'register'),
...
);
}
UserController
public function actionRegister()
{
$model=new User;
if(isset($_POST['User']))
{
$model->attributes=$_POST['User'];
if($model->save()){
$this->redirect(array('login'));
}
}
...
$this->render('register');
}
View - register.php
<?php $this->widget('CCaptcha'); ?>
<div class="captcha"><?php echo CHtml::activeTextField( $model,'verifyCode', array('class'=>'captcha')); ?></div>
<?php echo $form->error($model,'verifyCode'); ?>
This renders the captcha alright but the validation does not happen. What could be the problem?
Upvotes: 0
Views: 4357
Reputation: 1031
i think your problem is with on=>register try 'on'=>'insert' and read
http://yiiframework.com/forum/index.php?/topic/25817-rules-models/
and
http://php-thoughts.cubedwater.com/2009/validation-scenarios/
and
http://www.yiiframework.com/forum/index.php?/topic/13572-how-to-define-scenarios/
Upvotes: 3