php - Validation rule for file upload in update Scenario -


i have file upload option in form. have added field in model , added vlaidation rules below.

[['file1'], 'file', 'skiponempty' => false, 'extensions' => 'pdf,png,jpg', 'maxsize' => "10485760", 'toobig' => "maximum upload file size 10mb"] 

in edit mode, file field not required. need skip required field validation update scenario if user choose file in update form, extension, size need validated.

i changed rule below.

[['file1'], 'file', 'skiponempty' => false, 'extensions' => 'pdf,png,jpg', 'maxsize' => "10485760", 'toobig' => "maximum upload file size 10mb", "on" => ["insert"]],   [['file1'], 'file', 'skiponempty' => true, 'extensions' => 'pdf,png,jpg', 'maxsize' => "10485760", 'toobig' => "maximum upload file size 10mb", "on" => ["update"]],  

but still asking upload file in edit form.

thanks

try below rules

[['file1'], 'file', 'skiponempty' => true, 'extensions' => 'pdf,png,jpg', 'maxsize' => "10485760", 'toobig' => "maximum upload file size 10mb"], [['file1'], 'required', 'on' => 'insert'], 

add scenario in create action not in update

$model->scenario = 'insert'; 

Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -