Scenario: When users click the "log out" link, I'd like a confirmation form to pop up asking them to click again "yes" to confirm and continue logging out.
Is there module that does this? Or some kind of Rules workflow?
Use jQuery
Pop-up
(function ($, Drupal, window, document, undefined) {
$(document).ready(function(){
$('a[href="/user/logout"]').click(function(e){
if(!confirm("Are you sure you want to log out?")) { e.preventDefault(); }
});
});
})(jQuery, Drupal, this, this.document);
Or text replace
(function ($, Drupal, window, document, undefined) {
$(document).ready(function(){
$('a[href="/user/logout"]').click(function() {
$(this).removeClass('confirm');
$(this).text("Are you sure?");
$(this).unbind();
return false;
});
});
})(jQuery, Drupal, this, this.document);
Simple Middle Page
One very simple way to accomplish this would be to create a new page with a simple confirmation message.
For example: Are you sure you want to <a href='user/logout'>log out</a>?
Then link to your new page in whichever menu the log out link belongs.
Rules Link
There is a Rules Link module that can create links with JavaScript confirmations, as well as links that use confirm_form() You could automatically attach a log out link with confirmation to the User entity.
The l() Function
You may also be able to implement the l() function to generate the link you need.
$logout_link = l("Logout", "user/logout", array( 'onclick' => 'return confirm( "Are you sure?" ); ' ) );
Form API
You could use the Form API with a custom submit handler/redirect.
$form['logout'] = array(
'#type' => 'submit',
'#value' => t('Logout'),
'#attributes' => array('onclick' => 'if(!confirm("Really Logout?")){return false;}'),
);
Depending on how custom you want it, a simple JavaScript popup could work just fine:
$('a.logout-link').click(function(e){
var result = confirm("Are you sure you want to logout?");
if(!result){
// Stop the link from working.
e.preventDefault();
}
});
If you wanted to do something more custom, you could create your own popup and style with CSS. Not sure what your programming level is with Drupal.. But the JavaScript is simple enough :)
logout-link
class applied first?
Commented
Jul 27, 2012 at 3:17