bettor, on 01 March 2010 - 04:23 AM, said:
this
'on' => 'create'
means on create scenario not on register. This
'on' => 'register'
would mean on register scenario which you don't have in your code.
So with your current code in order to validate the required validator for your password you should define in your action $model->scenario='register'...than validate.
If this does not help please paste some of your action code where you handle your password...etc. The rest of your validators work because you have not setup any scenario....so they are validated in all cases.
Cheers,
bettor
hi sir. thanks for reply. here is some of my action controller
public function actionUpdate(){
$id = (int) $_GET['id'];
$Criteria = new CDbCriteria();
$Criteria->condition = "id = '$id'";
$model = SuperAdmins::loadModel($Criteria);
$this->render('update', array(
'model' => $model,
'action' => array('admin/update_process')
));
}
public function actionUpdate_Process(){
$id = (int) $_POST['id'];
$Criteria = new CDbCriteria();
$Criteria->condition = "id = '$id'";
$model = SuperAdmins::loadModel($Criteria);
$model->attributes = $_POST['SuperAdmins'];
$model->password1 = $_POST['password1'];
$model->password2 = $_POST['password2'];
$model->password = $model->password1;
$updated = array();
if(!empty($model->password)){
$updated[] = 'password';
}
$updated[] = 'username';
$updated[] = 'email';
$updated[] = 'display_name';
$updated[] = 'status';
$updated[] = 'edited_time';
$updated[] = 'edited_by';
if($model->validate($updated)){
if($model->update($updated)){
Yii::app()->user->setFlash('message','Data Saved');
$this->redirect(array('admin/list'));
}else{
Yii::app()->user->setFlash('message',CHtml::errorSummary($model));
$this->redirect(array('admin/update','id' => $id));
}
}else{
Yii::app()->user->setFlash('message',CHtml::errorSummary($model));
$this->redirect(array('admin/update','id' => $id));
}
}
I want to update some of data (admin user) including the password. but if the password field is not filled it will be ignored (optional).
and here is my model's rule
public function attributeLabels(){
return array(
'username' => 'Username',
'email' => 'Email',
'password1' => 'Password',
'password2' => 'Confirm Password',
'display_name' => 'Display Name',
'status' => 'Status'
);
}
public function rules(){
return array(
array('username,email,password1,password2,display_name,status','required'),
array('email','email'),
array('username','length','max' => 15),
array('password1','compare','compareAttribute' => 'password2')
);
}
thank sir. I hope this script is enough and easy to understanding about my problems that I get now
thanks