"Empty" Password-Field passes all validation rules -> Why is that?

Hey,

I have 5 validation rules for my password field (listed below)

When I update my password and leave the password-field completly blank

NO input error shows up… It passes the validation rules and gets saved in the DB.

When I check the DB the Password field actually is completly empty…

When I give input such as "ds$6" validation errors show up!

Why does an empty Password field pass the validation?!

MODEL




			array('password','match', 'pattern'=>'#^[0-9A-Za-z]+$#', 'message'=>'Only the following characters are allowed: 0-9 A-Z a-z', 'on'=>'update' ),

			array('password','length','max'=>25, 'on'=>'update'),	// PW only 20 Chars

			array('password','length','min'=>6, 'on'=>'update'),	// PW min 6 Chars

			array('password','compare', 'on'=>'update'),		//  -> PASSWORD REPEAT

			array('password_repeat','safe', 'on'=>'update'), 	//  -> PASSWORD REPEAT



Controller:




	public function actionUpdate($id)

	{

		$model=$this->loadModel($id); 

		$model->setScenario('update');




		// Uncomment the following line if AJAX validation is needed

		// $this->performAjaxValidation($model);


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

		{

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

			if($model->save())

			{

				Yii::app()->user->setFlash('success',"Data saved!");  	

				$this->redirect(array('view','id'=>$model->idUser));	

			}

		}


		$this->render('update',array(

			'model'=>$model,

		));

	}



Add a required rule.


array('password, password_repeat', 'required', 'on' => 'create'),

Matt

maybe what you need is allowEmpty to be true


array('password, password_repeat', 'allowEmpty'=>true, 'on' => 'update'),

not tested yet though

Yes THX…

The ‘allowEmpty’ was the thing that was missing!