Hi,
I would like to have a logout confirmation modal for user to confirm before logging out ?
How can I do it please ?
You may use Page_Render server event to change the logout URL, e.g.
SetClientVar("login", ["logouturl" => "return myLogout();"]);
You can put your logout function in client side global code, e.g.
window.myLogout = function () {
// Your code to show modal
// ...
if (result) window.location="/mypath/logout";
return false;
}
Hi,
It doesn’t works. When I add this code SetClientVar(“login”, [“logouturl” => “return myLogout();”]); in Server Events → Global → All pages → Page_Rendering , my logout icon disapears and no way to dropdown for logout button.
Help please !
You may post your related complete code just like given by arbei above.
Ok, here my code :
Server Events->Global->All pages->Page_Rendering :
SetClientVar("login", ["logouturl" => "return confirmLogout();"]);
Client Scripts->Global->Global code
let modalhtml = `<div class="modal fade" id="confirmlogout" tabindex="-1" role="dialog" aria-labelledby="confirmlogout" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="ModalLabel">Déconnexion</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
Etes-vous sûrs de vouloir mettre fin à votre session ?
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Annuler</button>
<button type="button" class="btn btn-primary">OK</button>
</div>
</div>
</div>
</div>`;
$("#mydiv").append(modalhtml);
window.confirmLogout = function() {
$('#confirmlogout').modal('show');
$('#confirmlogout').on("click", ".btn-secondary", function() {
$('#confirmlogout').modal('hide');
});
$("#confirmlogout").on("click", ".btn-primary", function() {
$('#confirmlogout').modal('hide');
window.location = "logout";
});
}
What is mydiv? Where is it? When you append something to it, then it should be already existed before.
Hi,
Yes “mydiv” already exist. It’s a customized div under adminlte header.
I just append my modal html (“modalhtml”) after “mydiv”.
But understand that I can’t post all my code (too long). I just posted the code related to the topic
At this stage, I can’t even test because the logout icon disappears and I don’t have access to the “Logout” button in the dropdown list
- It should be “logoutUrl”, not “logouturl”.
- Your function should return false if the user clicks the “Cancel” button,
- The code:
$('#confirmlogout').on("click", ".btn-secondary", function() {
$('#confirmlogout').modal('hide');
});
is not required because you already have data-dismiss=“modal”.
4. You better append your modal to $(“body”).
5. Right click the user panel and select Inspect in Chrome to check the HTML source and make sure your logout URL is correctly rendered.
6. Press F12 to check for JavaScript error.
Sorry
I corrected my code: “logoutUrl”,
SetClientVar("login", ["logoutUrl" => "return confirmLogout();"]);
but still the same result!
I still haven’t found a solution to my issue.
At this point, my modal window appears, but is immediately closed before the login form appears.
Help please !!!
Note that the login form is another page. The modal dialog is in the previous page.
Ok, I understand better why the modal does not stay displayed? How should I proceed then? Any ideas?
Hello all.
I’m reviving my topic because I still haven’t found a solution to allow the user to confirm when he wants to disconnect.
Maybe someone has already managed to implement this feature in his application.
Really need help.
I am using the latest version of phpmaker.