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
Post a Comment