Hi
I make a register action in site controller like
public function actionRegister()
{
$register = new User;
$register->scenario = 'register';
// collect user input data
if (isset($_POST['User'])) {
$register->attributes = $_POST['User'];
$register->scenario = 'register';
echo $_POST['User']['captchaCode'];
// validate user input and redirect to previous page if valid
if ($register->validate()) {
$register->lastLoginIp = $register->getRealIpAddress();
$register->lastLoginDate = time();
$register->password = hash('whirlpool', $_POST['User']['password']);
$register->save();
Yii::app()->user->setFlash('Sign Up!','Thank you for signing up. We will send an activation link by email to you as soon as possible.');
$this->refresh();
}
}
// display the login form
$this->render('register', array('register' => $register));
}
and a user class based on class which yiic shell made it for me >>model User from user tabel and I change the rule
public function rules()
{
return array(
array('username', 'length', 'min' => 3, 'max' => 100, 'on'=>'register'),
array('password','length', 'min' => 6, 'max' => 128, 'on'=>'register'),
array('password2','compare','compareAttribute'=>'password', 'on'=>'register'),
array('email', 'length', 'max' => 150, 'on'=>'register'),
array('email', 'email', 'on'=>'register'),
array('email2','compare','compareAttribute'=>'email', 'on'=>'register'),
array('url', 'length', 'max' => 250, 'on'=>'register'),
array('url','url', 'on'=>'register'),
array('name', 'length', 'max' => 150, 'on'=>'register'),
array('family', 'length', 'max' => 150, 'on'=>'register'),
array('address', 'length', 'max' => 250, 'on'=>'register'),
array('pobox', 'length', 'max' => 15, 'on'=>'register'),
array('telephone', 'length', 'max' => 30, 'on'=>'register'),
array('cellphone', 'length', 'max' => 30, 'on'=>'register'),
array('captchaCode', 'captcha', 'allowEmpty'=>!extension_loaded('gd')),
array('username, password, email, name, family', 'required', 'on'=>'register'),
);
}
and add some attribute
public $password2; public $email2; public $captchaCode;
and in view file make something like this
<?php if (extension_loaded('gd')): ?>
<div class="simple">
<?php echo CHtml::activeLabelEx($register, 'captchaCode'); ?>
<div>
<?php $this->widget('CCaptcha'); ?>
<?php echo CHtml::activeTextField($register, 'captchaCode'); ?>
</div>
<p class="hint">Please enter the letters as they are shown in the image above.
<br/>Letters are not case-sensitive.</p>
</div>
<?php endif; ?>
but when I submitting the form with correct text for captcha image validator make an error message which The verification code is incorrect.
would you plz help me.