Hi,
I have a form that has a file field, the file is required so I’m setting ‘allowEmpty’ => ‘false’. The problem is that the Ajax Validation keep telling that field is no valid even after selecting a file.
How to solve this?
View
<?php
$form = $this->beginWidget('CActiveForm', array(
'id' => 'file-form',
'enableAjaxValidation'=>true,
'clientOptions'=>array('validateOnSubmit'=>true, 'hideErrorMessage'=>true),
'htmlOptions' => array('enctype' => 'multipart/form-data'),
));
?>
.....
<?php echo $form->fileField($model, 'file_path'); ?>
Controller
public function rules() {
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('name', 'required'),
array('name', 'length', 'max' => 250),
array('file_path', 'file',
'types'=>'pdf,txt,doc,docx',
'maxSize'=>1024 * 1024 * 50,
'allowEmpty' => false),
array('id, name, file_type, file_path', 'safe', 'on' => 'search'),
);
}
Thank you