Required On Of Them Field Model

Hi to everyone

I want to promt the user to upload a file or choose a url.

For example: when a file uploaded or a text is filled by the user then the Model will be signed as validated.

How to achieve this ?

I cannot set the rules of model like that

array('fileupload, theurlurl', 'required')

because in this case both of two field will be required but I want one of them to be required - not both of them simultaneously.

In addition how to do that on new or update scenario ?

Thanks a lot :)

assign scenario based on update values (Need or not)

// When add create, We have to give password and password

$model=new User;

$model->scenario ='insert';



//When update use update scenario, We dont need to give password


$model->scenario ='updateuser';

In model


array('username, password,confirmpassword,firstname,lastname', 'required','on'=>'insert'),

 array('username, firstname,lastname', 'required','on'=>'update '),

Hi mbala

First thank you for the quick response

May be I didn’t say very clear what I want

The scenario that I mentioned is not relative with the required on of them of field,

but for extra functional that I not mentioned.

The main functionality will be applied both of scenario

I explained What i understood. your form have two fields fileupload, theurlurl. So You must have to choose one of the field. Better way to write custom validation function in model.

public function my_required($attribute_name,$params){

if((isset($this->fileupload) && $this->fileupload!='') && (isset($this->theurl) && isset($this->theurl))){




Thank you mbala, I manipulated it with below code

    public function beforeValidate() {


        if (!$this->myfile && !$this->urlfile) {

            $this->addError('myfile', 'You have to fill the url or upload a file');


        return parent::beforeValidate();


Is it possible to make a site theme. 10 Themes allow for the circulation of each one of them is active and the other theme Home screen is different.

Thank you