简体   繁体   中英

How to create a confirm dialog box before submit in Yii framework

I'm new to Yii framework, I need to create a confirm dialog to pop up before I submit a form. Below is the code of the form used to approve and reject. I need a pop up to appear before I submit to confirm whether approved or rejected.

<div class="row">
        <?php echo $form->labelEx($model,'Approved'); ?>
<?php
 echo $form->radioButtonList($model, 'Approved',
                    array(  1 => 'Approved',
                            0 => 'Rejected',
 ),

                   array(
    'labelOptions'=>array('style'=>'display:inline'), // add this code
    'separator'=>'  ',
) );


?>


        <?php echo $form->error($model,'Approved'); ?>
    </div>  

Edit

<div class="row buttons">
        <?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
    </div>

How can I achieve this

You can add htmlOptions into your submitButton like:

 <?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save',
    array('confirm'=> 'Are you Sure')); ?>

It will show a confirm dialog when you click submitButton.

<?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', [
    'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary',
    'data' => [
        'confirm' => 'Are you sure want to Create/Update this message?'
        ]
    ]) ?>

Use data attribute.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM