Validate Filefield

Is it possible to validate the type of a fileField before it’s uploaded?

I’ve a form without db model (CFormModel). These are the rules




public function rules() {

        // NOTE: you should only define rules for those attributes that

        // will receive user inputs.

        return array(

            array('bilancio_csv', 'required'),

            array('bilancio_csv', 'file', 'types' => 'csv', 'wrongType'=>'Only csv allowed.'),

        );

    }



When i load the file and submit form, the "required" rule works perfectly, but not the other one.

This is the form code




<?php

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

        'id' => 'importa_bilancio_csv',

        'enableAjaxValidation' => false,

        'enableClientValidation'=>true,

	'clientOptions'=>array(

		'validateOnSubmit'=>true,

	),

        'htmlOptions'=>array(

            'enctype'=>'multipart/form-data',

        )

    ));

    ?>

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

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

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

    <div class="row buttons">

    <?php echo CHtml::submitButton('Importa Dati dal File Caricato'); ?>

    </div>

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



do you also have the controller code?