How to define rules for password confirmation only if user entered a value for it

I have an existent user with a password in the database.

There is an update form that he can use to update some data.

I want the followings:

a) the password and password confirmation fields to be rendered as empty (password should be printed to screen)

B) when the user leaves empty both of the fields, it should not validate the password change request (skip it)

c) when the user types in some value in the password field, to be validated and prompted to type for confirmation (they sometime miss them)

d) if the password has been typed in correctly in both of the fields, then to proceed with save.

I am having trouble to validate c) and not validate B) on the same form.

I am after something

if not empty password -> confirm password required + must match password

Also how should I define password_confirm to be able to get from the form directly into the model, without geting out via $_POST.


<?php

class MyModel extends CModel{

	public $password_confirm='default_Value';

}

the rest of your questions you can find in the guide and [url=&quot;http://www.yiiframework.com/wiki/56/reference-model-rules-validation/&quot;]here

[/url]

I’ve read those pages and didn’t find the answer for the most important part:

Read here about scenarios.

I already make use of the scenarios, but can’t make it so to require one of the fields only when the other is present.

I want to flag a field required only when some other field has a value. Can be done?

So use required & compare validators on register let’s say and only compare on update?

Somehow similar

I need this




if (!empty($this->password) {

 array('confirm_password1', 'required', 'on' => 'update'),

 array('confirm_password1', 'compareOnUpdate', 'on' => 'update'),

}

as you this is only done when the password is not empty, that’s what I don’t know.