I’m trying to validate a field if a file fields is not empty. So if someone is trying to upload a file, I need to validate another field to make sure they selected what they are uploading, however I don’t know how to check to see, or run a rule only if the field is not empty.
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('full_name, gender_id','required'),
array('video', 'file', 'types'=>'mp4', 'allowEmpty' => true),
array('audio', 'file', 'types'=>'mp3', 'allowEmpty' => true),
array('video','validateVideoType'),
);
}
public function validateVideoType() {
print_r($this->video);
Yii::app()->end();
}
So this->video is always empty whether I just uploaded something or not. How do I check to see if that variable is set?
Custom validation function must be defined properly. It has two parameters always
$attribute&$params.Now in this you should write your custom way to validate.
I am sure that would work fine.