File Field 'required' Validation

I am trying to ensure a file field is ‘required’ using ajax validation. I have the following:

View (simplified):

<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(











)); ?>

<?php echo $form->errorSummary($model); ?>

<div class="row">

	<?php echo $form->labelEx($model, 'image_upload'); ?>

	<?php echo $form->fileField($model, 'image_upload'); ?>

	<?php echo $form->error($model, 'image_upload'); ?>


<div class="row buttons">

	<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>


<?php $this->endWidget(); ?>



// public attribute

public $image_upload;

// validation rule

array('image_upload', 'required'),

The problem is, even when I have selected a file, it fails validation and the error message is displayed. It is not possible to proceed in the form.

I have also tried the ‘file’ validator using ‘allowEmpty’=>false but this does not work either.

I am using version 1.1.14



solution for your problem is here

you cannot use required rule for file field

Thanks. Is there any workaround?

I need the field to be marked as required (with asterisks) and also if the user does not select a file and just clicks on Submit it needs to show error.


It can help you to solve ur problem

To check for required condition

allowEmtpy set to false …then it is required field