I have a menu item that exits the main app and redirects to login. I would like for it to display a confirmation dialog “Are you sure you want to logout? Any unsaved data will be lost”. Would I be able to achieve this with blank php? The only three events available in menu don’t allow “Display an error message” or “Display a message”. Would this be achievable with a PHP method? Is there anything to disallow a method from being called on one of the three menu events? I haven’t tried working with PHP methods in SC yet so I have no idea.
Hi Ancr2001,
Yes you can display a confirmation dialog.
[SIZE=5]Example Logout confirmation dialog box[/SIZE]
- You need a blank application with this PHP Script using javascript:
echo "<script>
if (confirm('Your question')) {
window.location='DESTINATION';
}else{
// do other thing
}
</script>";
- Replace ‘DESTINATION’ to your login app, example: ‘…/login_app/’;
- Your logout link must point to this blank application.
Thanks!
I got it working but I need it to kill the session when you click OK. How do I do that since you can’t put a macro in the script. Right now the else redirects to the login app and cancel takes you back to the menu. If I choose OK and click back and refresh after the redirect the menu comes back and the session is still active.
Ancr2001,
You can redirect using parameters.
[SIZE=5]Example to kill / destroy session[/SIZE]
Replace your ‘DESTINATION’ with your login app like ‘…/login_app/login_app.php?logout=1’; as you can see i add a ‘?logout=1’, now in your login app you must destroy the session onload.
//ONLOAD
if($_GET['logout']==1){
session_destroy();
}
Note: When your user is redirected with logout=1 the session will be destroyed.
Thanks! Works great. I had to modify the code a little because I was getting an undefined index error but now it works like a charm!
if(isset($_GET['logout'])){($_GET['logout']==1);
session_destroy();
}