We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

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



93.7k
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...