title: Yii file upload - filefield not validated
body: <p>I am kinda new to yii and I'm having problem with file upload.
  When I upload a file it doesn't validate - it allows all types (it shouldn't), allows empty (it shouldn't as well) etc. 
  Of course I included proper rules (I think) in my model.
  It looks like fileField is not validating for some reason.</p>
  
  <p>I want it to write error message (wrong type or empty) when I click on Submit button.
  Please take a look at it if you can't find anything wrong.</p>
  
  <p>Here is my form:</p>
  
  <pre><code>&lt;?php class UploadSolutionForm extends CFormModel
      {
  
  public $sourceCode;
  
  public function rules()
  {
      return array(
          array('sourceCode', 'file', 'types'=&gt;'java, zip', 'allowEmpty'=&gt;false, 'wrongType'=&gt;'Only .java and .zip files.'),
      );
  }
  
  /**
   * Declares attribute labels.
   */
  public function attributeLabels()
  {
      return array(
              'sourceCode' =&gt; 'Source code',
      );
  }}
  </code></pre>
  
  <p>Here is my action in controller:</p>
  
  <pre><code>public function actionSolveProblem()
  {
      //gets id from url
      $id = Yii::app()-&gt;request-&gt;getQuery('id');
  
      //guests can't work with problems in any way
      if (Yii::app()-&gt;user-&gt;isGuest)
      {
          $this-&gt;redirect(array('site/index'));
          return;
      }
  
      if(isset($id))
      {
          $model = new UploadSolutionForm();
  
          if(isset($_POST['UploadSolutionForm']))
          {
              $model-&gt;attributes=$_POST['UploadSolutionForm'];
  
              $newFile = CUploadedFile::getInstance($model, 'sourceCode');
  
              $problem = Problems::model()-&gt;findByAttributes(array('id'=&gt;$id));
  
              $version = Solutions::model()-&gt;countByAttributes(array('id_problem'=&gt;$id))+1;
  
              $pathUser = Yii::app()-&gt;basePath.'\\SubjectFolder\\'.$problem-&gt;id_subject.'\\'.$id.'\\'.Yii::app()-&gt;user-&gt;getName();
  
              $path = $pathUser.'\\'.$version;
  
              if (!is_dir($pathUser)) {
                  mkdir($pathUser);
              }
              if (!is_dir($path)) {
                  mkdir($path);
              }
  
              $uploadPath = $path.'\\'.$newFile-&gt;name;
  
              $solution = new Solutions();
              $solution-&gt;id_problem = $id;
              $solution-&gt;id_user = Yii::app()-&gt;user-&gt;getId();
              $solution-&gt;submit_time = date("Y-m-d H:i:s",time());
              $solution-&gt;path_to_file = $uploadPath;
              $solution-&gt;version = $version;
  
              if($newFile-&gt;saveAs($uploadPath))
              {
                  if($solution-&gt;save())
                  {
                      Yii::app()-&gt;user-&gt;setFlash('new_problem','Solution uploaded');
                      $this-&gt;redirect(array('site/problems'));
                  }
                  else
                  {
                      Yii::app()-&gt;user-&gt;setFlash('new_problem','Error! Could not save into db');
                      $this-&gt;redirect(array('site/problems'));
                  }
  
              }
          }
  
          //part bellow is not really important in this case
  
          $auth = Problems::model()-&gt;with(array('subject','subject.currentUserSubject' =&gt; array('alias'=&gt;'currentUserSubject')))-&gt;findByAttributes(array('id'=&gt;$id));
  
          // user with proper role cannot upload solutions to problems
          if($auth!=null)
          {
              $this-&gt;render('solve',array('model'=&gt;$model));
          }
          else
          {
              Yii::app()-&gt;user-&gt;setFlash('new_problem','You are not authorized to upload a solution for this problem');
              $this-&gt;redirect(array('site/problems'));
          }
  
      }
  
  
  }
  </code></pre>
  
  <p>And here is my view (solve.php):</p>
  
  <pre><code>&lt;?php 
  $form = $this-&gt;beginWidget(
          'CActiveForm',
          array(
                  'id' =&gt; 'upload-form',
                  'htmlOptions' =&gt; array('enctype' =&gt; 'multipart/form-data'),
                  'enableClientValidation'=&gt;true,
                  'clientOptions'=&gt;array(
                          'validateOnSubmit'=&gt;true,
                          ),));
                  ?&gt;
  
  &lt;div class="row"&gt;
      &lt;?php echo $form-&gt;labelEx($model, 'sourceCode');?&gt;
      &lt;br&gt;&lt;?php echo $form-&gt;fileField($model, 'sourceCode');?&gt;
      &lt;?php echo $form-&gt;error($model, 'sourceCode');?&gt;
  
  &lt;/div&gt;
  
  &lt;div class="row buttons"&gt;
          &lt;?php echo CHtml::submitButton('Submit'); ?&gt;
      &lt;/div&gt;
  &lt;?php 
  // ...
  $this-&gt;endWidget();?&gt;
  </code></pre>
  
  <p>I hope sombody can help because I looked all over and I just can't seem to find anything wrong.</p>
  
  <p>EDIT: I mainly want to figure out why client side validation isn't working correctly for file upload (it works for text fields) and of course fix it as well...</p>