This has happened to me several times:

  • I'll go to a node's edit form and begin making some changes but not finish them and leave the form open
  • go back to the browser tab with the node's edit form later that day or the next day when the session is actually expired, so if I was to click any admin link I would get logged out, but I don't click any links because I'm editing text on the node's edit form
  • finish re-writing the article and click save.
  • get logged out and redirected to homepage, no changes made on the node's edit form get saved (then I laugh sinister at my own foolishness and suffering)

By now I know that I need to be aware of this and either ensure I'm logged in via a separate browser tab/window, or copy/paste the node's text to a file before trying to save the node. And I could lessen the frequency this happens by changing the session expiration time (which I don't know how to do but could figure out).

But I have no idea what to do in a graceful way that would prevent users from loosing their work in this scenario.

I don't see a module for this, or anything solution for these circumstances here or StackOverflow.

Any ideas?

Comments

VM’s picture

extend session life time in settings.php or investigate modules like https://www.drupal.org/project/session_cookie_lifetime

ahillio’s picture

right...

Thanks @VM, I mention that as a way to decrease the frequency in which this happens. But it doesn't account for when it still does happen.

I wonder if there could be some AJAX call to see if the session's status is expired, and if it is then present a modal login form so the user can log back in without losing edits on the form?

That's a vague guess of a possible solution. I don't know if it would work, if it would be easy or quite difficult.

I had imagined this AJAX call running periodically (every minute?) but maybe that would be resource intensive? Maybe it could happen when the save button is clicked before the form gets submitted?

It seems like something people must have dealt with before...? I'd love to know how.

Jaypan’s picture

You don't need an AJAX call, you can use local storage if you want to save it: http://www.w3schools.com/html/html5_webstorage.asp

Just set your code to save to local storage periodically, every minute or so. Then you can load from localstorage when the node form is loaded.

ahillio’s picture

Oh, local storage! I hadn't heard of that before. Now I'm starting to get some results as I look around: https://www.drupal.org/project/garlic and https://www.drupal.org/project/local_storage on first glance. Thanks Jaypan!