Recent Changes - Search:

Cookbook

PmWiki

pmwiki.org

NotsavedWarning

Summary: Warn authors when they move away from a page without saving it. Optionally request an edit summary or an author name.
Version: 20110829
Status: beta
Maintainer: Petko
Categories: Editing

Description

Warn authors when they move away from a page without saving it. It will optionally ask the user to fill a "Change summary" if it is empty.

It happens that authors modify a page, but instead of pressing the Save button, they click on a link that leads away from the edit form. In that case, all their changes are lost.

This recipe will display a confirmation dialog box, and the user can press "Cancel" to return to the edit form.

Demo - test the recipe here.

Installation

  • Copy notsaved.phpΔ to your /cookbook/ directory (alt. download: notsaved.php).
  • Add to config.php this code:
    if($action=='edit'){
      $NsPromptSum    = XL("Please enter a summary"); # Optional, read below.
      $NsPromptAuthor = XL("Please enter your name"); # Optional, read below.
      include_once("$FarmD/cookbook/notsaved.php");
    }

The lines $NsPromptSum = "Caption"; and $NsPromptAuthor = "Caption"; are not required. Each will cause a "prompt" box to appear if the form is submitted with an empty "Summary" or "Author" field.

It just reminds to enter a summary (or an author), without enforcing one -- if the user fills nothing, the form is still submitted.

Other config.php variable (before the include_once line):

  # disable the warning if a user leaves the edit form
  $NsWarning = false;

  # custom warning message
  $NsWarning = XL("Abandon changes and exit?");

Notes

  • The dialog box is done in JavaScript, so the authors need to have recent browsers with JavaScript enabled.
  • Browsers which do not recognize the OnBeforeUnload Event, may not work. (Mozilla, MSIE and Chrome work, Konqueror and Opera don't seem to.)
  • The confirm box will only show if the content in the edit form is actually modified. It works with all text fields, so the Edit Attributes recipe works fine, and possibly other recipes enhancing the edit form.

Release Notes

  • 20110829 : It should now work with the MiniEdit recipe.
  • 20110616 : Adaptation for an alternative edit form.
  • 20090612 : Fix: MSIE versions 7 and 8 block the "prompt" box where the user types their name/summary (reported by David Pilling). To those users, now the recipe shows simple "alert" box with the message and blocks the form post.
  • 20090428b : Fix: removed warning on pressed Cancel.
  • 20090428 : Add: $NsWarning; Fix: the form is not submitted if the user pressed Cancel on the prompt box; Fix: no prompt box on preview or cancel button.
  • 20090425d : Fix captions to allow apostrophes.
  • 20090425c : Changed the install format to allow the setting of captions.
  • 20090425b : Add $NsPromptAuthor.
  • 20090425 : Add $NsPromptSum - optional prompt box to enter a change summary.
  • 20090311 : Fix for Preview mode.
  • 20090307 : First public release, ready to be tested.

See Also

Author

The recipe is written and maintained by Petko.

Comments

Your comments are welcome.

User notes +4: If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.

Edit - History - Print - Recent Changes - Search
Page last modified on October 24, 2011, at 10:13 AM