Hi,
I have a rather complex validation requirement.
A Portfolio must have at least one image associated with it. If there isn’t an image associated with it, I need to make the File Input required. Once the user has submitted a file I need to validate it against CFileValidator.
Pseudo Code:
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('imageList', 'validateFile', 'on' => 'manageImages');
}
public function validateFile()
{
$fileValidator = CValidator::createValidator('CFileValidator', $this, 'imageList');
if (count($this->images) === 0)
{
CMap::mergeArray($this->rules(),
array(array('imageList', 'file', 'types' => 'jpg, gif, png',
'allowEmpty' => false, 'maxFiles' => 4)));
}
else
{
CMap::mergeArray($this->rules(),
array(array('imageList', 'file', 'types' => 'jpg, gif, png',
'allowEmpty' => true, 'maxFiles' => 4)));
}
$fileValidator->validate($this, array('imageList'));
}
Notice that if there are no images associated with the Portfolio, allowEmpty = false.
Could someone point me in the right direction to get this started?
Cheers.