Yii Framework Forum: File validation - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

File validation

#1 User is offline   vyckiuz 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 16-November 16

Posted 17 November 2016 - 03:57 AM

Hello, I have problem with file validation

View:
<?php $form = $this->beginWidget('CActiveForm', [
'id' => 'help-form',
'enableAjaxValidation' => false,
'htmlOptions' => array('enctype' => 'multipart/form-data'),
]); ?>

<?= $form->fileField($model, 'receipt_copy'); ?>


Model rules:
...
['receipt_copy', 'file', 'allowEmpty'=>true, 'types'=>'jpg, gif, png', 'message' => 'wrong format'],
...


Other fields work normal by specified rules, but receipt_copy file field in not working. Why? When I add txt file and submit no errors is showing and form passes.

When i delete 'allowEmpty'=>true form never passes and all the time the error is showing, so maybe someone can explain why the file is not recognized?

Edit:
Controller:
if (isset($_POST['TestForm']))
{
$model->attributes = $_POST['TestForm'];
$model->receipt_copy= CUploadedFile::getInstance($model, 'receipt_copy');
if ($model->validate())
{
$model->save();
}
}

model is saved, receipt copy = null.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users