php - Yii cant validate file input -


i'm doing project in php yii framework. have form requires user upload file. during registration, user uploaded file, however, when user submits form, form detected blank on file input, it's if there no attachment on form. below code:

model - candidateresume:

return array(                  array('resume_file','file','types'=>'doc,docx,pdf', 'allowempty'=>true, 'safe'=>true, 'on'=>'register'), );  

model - candidate:

return array(       array('can_email,name,repeat_can_email, can_password,repeat_can_password','required', 'on'=>'simplereg'), ); 

view:

$form = $this->beginwidget('bootstrap.widgets.tbactiveform',array(     'id'=>'candidate-form',     'enableajaxvalidation'=>true,     'type'=>'horizontal',     'htmloptions' => array(             'enctype' => 'multipart/form-data',             'autocomplete'=>'off', //turn off auto complete in ff     ) ));   echo $form->textfieldrow($model,'can_email',array('class'=>'span5','maxlength'=>100));  echo $form->textfieldrow($model,'repeat_can_email',array('class'=>'span5','maxlength'=>100));  echo $form->passwordfieldrow($model,'can_password',array('class'=>'span5','maxlength'=>100));  echo $form->passwordfieldrow($model,'repeat_can_password',array('class'=>'span5','maxlength'=>100));  echo $form->filefieldrow($resume,'resume_file', array('id'=>'resume_file'));    $this->endwidget(); 

controller - candidate:

public function actioncreate() {     $model = new candidate();     $model->setscenario('simplereg');     $resume = new candidateresume();     $resume->setscenario('register');         // uncomment following line if ajax validation needed     //$this->performajaxvalidation($model);      if(isset($_post['candidate'], $_post['candidateresume']))     {         $_post['candidateresume']['resume_file'] = $resume->resume_file;         $model->attributes = $_post['candidate'];         $resume->attributes = $_post['candidateresume'];          $uploadedfile = cuploadedfile::getinstance($resume,'resume_file');                    if($resume->validate() && $model->validate())          {             $model->save();              if(!empty($uploadedfile))  // check if uploaded file set or not             {                 $saved = $uploadedfile->saveas(yii::app()->params['resume_path'].$model->can_id.'_'.$uploadedfile->getname());                 $resume->resume_file = yii::app()->params['resume_dir'].$model->can_id.'_'.$uploadedfile->getname();                 $resume->resume_send_ip = yii::app()->request->userhostaddress;             }             $resume->save();          }     }      $this->render('create',array('model'=>$model, 'resume'=>$resume)); } 

if remove validation on controller:

if($resume->validate() && $model->validate())  

the form data can saved , attachment placed in folder. however, need validation form. therefore cant skip part.

is there missed out? have checked many times , researches solutions. provides similar solutions, therefore can't figure out things. can me? thank in advance.

you don't set resume_file attribute. cames $_files not $_post

$resume->attributes = $_post['candidateresume']; $uploadedfile = cuploadedfile::getinstance($resume,'resume_file');    $resume->resume_file = $uploadedfile; //add line 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -