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

user2770039 picture user2770039 · Sep 24, 2013 · Viewed 8.6k times · Source

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

Answer

secretlm picture secretlm · Sep 24, 2013

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.