1
  1. I have an upload excel to DB form.

  2. It has 1 File input and 2 buttons 'Upload' and 'Delete All'.

Problem Scenario:

I don't want client-side activeform validation on 'Delete All' as File is not required here.

Code:

<?php $form = ActiveForm::begin([ 'enableClientValidation' => false, 
            'options' =>['action' => Url::toRoute('/site/halltickets')
                        ,'method' => 'POST'
                        , 'enctype'=>'multipart/form-data']]); ?>

<?= $form->field($model, 'file')
    ->fileInput()->label("Upload Only Excel File [Allowed Formats: xlsx, xls]") ?>
<center>
    <?= Html::submitButton('Upload &raquo;', ['class' => 'btn btn-warning']) ?>
    <?= Html::a('Delete All &raquo;',
        Url::toRoute(['site/delete-halltickets']),
        ['class' => 'btn btn-danger',
            'data-confirm' => Yii::t('yii', 'Delete all Hall Ticket Allocations?'),
        ]);?>
</center>
<?php ActiveForm::end(); ?>

to understand better, below is the image.

enter image description here

Ankur Soni
  • 5,725
  • 5
  • 50
  • 81

1 Answers1

0

It is bad idea to place "Delete All" button on the upload form. Insert this button outside the form. It will more user-friendly.

Additionally you can remove "required" validator from model. Or define it only for the specific scenarios.

IStranger
  • 1,868
  • 15
  • 23