Alec Gamble
Alec Gamble

Reputation: 461

Yii Framework - Delete Multiple, sending form results

At the moment I've got a function where I can delete multiple items from my database from a CGridView which is working fine. The only problem is that I want to direct the user to a confirmation page before deleting the items.

How do I do that?

Upvotes: 1

Views: 94

Answers (2)

musafar006
musafar006

Reputation: 989

Do you mind using a javascript confirm box? If yes, in your first view change

<a class="btn btn-danger"><?php echo CHtml::SubmitButton('Delete Selected'); ?></a>

to

<a class="btn btn-danger">
  <?php echo CHtml::SubmitButton('Delete Selected', array('confirm' => 'Are you sure you want to delete?')); ?>
</a>

EDIT: If changing style is not an issue. The above part still works.

Also, I think you can change a tag and use the bootstrap classes in button.

<?php
    echo CHtml::SubmitButton('Delete Selected',
    array(
        'confirm' => 'Are you sure you want to delete?',
        'class' => 'btn btn-danger'
    ));
?>

Upvotes: 0

ScaisEdge
ScaisEdge

Reputation: 133380

You can do it in two steps:

  1. Submit the value you need to delete at a first action. This action renders the data you want to show and then asks for confirmation or reject. (eg: active field not editable or hidden field that replies the value for submit)

  2. Use the confirm button of this view to submit confirmed data to the second action that will make deletions.

Upvotes: 2

Related Questions