I am wondering if there's a way to add confirmation message before executing an Action in Symfony2
.
I know that i can add a confirm message in html
like this :
<a href = {{ my_route }} onclick="return confirm('Are you sure do you want to delete this file?')>"
but the problem is that my page will not be included in any twig
file, so can i add the confirm message in my Controller class
?
EDIT
As i said in the comments my page will be used in Salesforce as a field named Details : I've already add my_url as javascript like this:
Details= "javascript:document.onClick = window.location.href = my_url"
and it works, but i still don't know how to add the confirmation message
to Details field
I don't think there is way to do that. The confirm message is an action that is performed client side. You can't add any action based message from PHP.
Where is your page will be included in ? if not in a Twig view
Edit:
I think this could help you : https://jsfiddle.net/5u6wepc5/
Html code
<div>
<input type="text" id="input" value="salesforce"/>
<input type="button" id="button" value="delete"/>
</div
Javascript code
$("#button").click(function(e) {
//this prevents that the form is submitted
e.preventDefault();
if(confirm('are you sure ?')) {
alert('clicked ok');
//do what you want here
} else {
alert('clicked cancel');
//do what you want here
}
});