phpyiiyii-components

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


Solution

  • 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.