Answer the question
In order to leave comments, you need to log in
[[+content_image]]
How to fix ajax validation of yii2 files?
There is ajax form validation.
my rules
[['passport_photos', 'oversea_passport_photos'], 'required', 'on' => 'vip'],
[['oversea_passport_photos', 'passport_photos'], 'file', 'skipOnEmpty' => false, 'extensions' => 'png, jpg', 'maxFiles' => 10]
$model = new Client();
$model->scenario = 'vip';
if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) {
Yii::$app->response->format = Response::FORMAT_JSON;
return ActiveForm::validate($model);
}
<?php $form = ActiveForm::begin([
'action' => '/order/default/vip-form',
'enableAjaxValidation' => true,
'enableClientValidation' => false,
'options' => [ 'enctype' => 'multipart/form-data']
]); ?>
<?= $form->field($model, 'passport_photos[]' )->widget(FileInput::className(), [
'options' => [
'multiple' => true,
'accept' => 'image/*'
],
'pluginOptions' => [
'allowedFileExtensions'=>[ 'jpg', 'png'],
'uploadUrl' => 'false',
'maxFileCount' => 10,
'initialPreviewAsData' => true,
'overwriteInitial' => false,
'showRemove' => false,
'showUpload' => false,
'fileActionSettings' => [
'showUpload' => false
]
]
]) ?>
<?= $form->field($model, 'oversea_passport_photos[]' )->widget(FileInput::className(), [
'options' => [
'multiple' => true,
'accept' => 'image/*'
],
'pluginOptions' => [
'allowedFileExtensions'=>[ 'jpg', 'png'],
'uploadUrl' => 'false',
'maxFileCount' => 10,
'initialPreviewAsData' => true,
'overwriteInitial' => false,
'showRemove' => false,
'showUpload' => false,
'fileActionSettings' => [
'showUpload' => false
]
]
]) ?>
<?= Html::submitButton(Yii::t('layout', 'signup'), ['class' => 'btn btn-submit']) ?>
<?php $form::end(); ?>
Answer the question
In order to leave comments, you need to log in
the problem is that these fields do not validate normally, how to fix it?
'skipOnEmpty' =>true
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question