Lithium: Show confirm box when link is clicked
-
10-12-2019 - |
Question
I have a lithium Html helper link
<?php echo $this->html->link('Delete', array('action' => 'delete', 'args' => $id); ?>
When this link is clicked I would like a confirm box to show up, but I can't see anything in the documentation that would allow me to do this.
Is this possible?
Solution
As provided by Dvir Volk this can be solved using the following:
<?php echo $this->html->link('Delete', array('action' => 'delete', 'args' => $id), array('onclick', 'return confirm("Are you sure you wish to delete this item?")'); ?>
OTHER TIPS
I would use jquery to add an event to it.
<?php echo $this->html->link (
'Delete',
array(
'action' => 'delete',
'args' => $id,
'class' => 'delete'
)
); ?>
<script>
$('a.delete').click(function(){
confirm("Are you sure you wish to delete this item?");
});
</script>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow