D
D
Dilik Pulatov2017-08-01 17:23:59
Yii
Dilik Pulatov, 2017-08-01 17:23:59

How to solve the problem of validation in Yii2?

Hello!
I have one problem.
the problem is that when submitting the form does not skip an application that does not have the require attribute
, when clicking on the submit, it will simply ask you to upload a file (but I don’t need it, you need to validate if you uploaded a file, and if you didn’t upload it, you just need to skip it) how to do this?

public $uploadFile;
  public function rules(){
    return [
      [['id','date','phone'], 'integer'],
      [['name','phone'], 'required'],
      [['name'], 'string', 'max' => 20],
      [['company','file'], 'string', 'max' => 255],
      [['uploadFile'], 'file', 'skipOnEmpty' => false, 'extensions' => 'pdf, cdr, zip, rar'],
    ];
  }

uploadFile - not in the database... this is necessary to validate the file
when submitting it should not check if the file is not uploaded
(sorry for errors)

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
M
Maxim Timofeev, 2017-08-01
@webinar

'skipOnEmpty' => false,
change to
'skipOnEmpty' => true

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question