Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Confirm in link_to

Hi guys

Is there any way to make a confirm popup/javascript/thing.. I have a CRUD, where I want the user to confirm deleting stuff..???

Regards



66.0k
Accepted
answer
edited Jul '16

Hey friend,

this is out of Phalcon's scope as it handles only your backend. However I can give you two solutions:

1) Use onClick attribute for the link:

{{ link_to(['for': 'your-route-name'], 'Delete Me', 'onClick': 'return confirm("Are you sure?");') }}

2) Or you could add a class to those links and do the rest with javascript:

{{ link_to(['for': 'your-route-name'], 'Delete Me', 'class': 'js-confirm-delete) }}
$('.js-confirm-delete').on('click', function(){
    // Here I have custom code which calls Twitter bootstrap modal
});

I'm using option 2 and it looks something like this. But it is all up to you:

Popup preview

of cause.. it's in Volt, I presume... but your solution is perfect.. thanks...