So autosave for comments would require making a new database table, I guess-- no revisions for comments.

But after my second user saying "I wrote this long comment and then hit backspace and it was gone– do you have it anywhere?" I really want autosave for comments before the third user says this!

So is their interest for this? Are the developers willing to add it? Suggestions on making a module that can hook into autosave and do this, and maybe be distributed with autosave?

Comments

Equinger’s picture

EXACTLY the same issue here. I'm not sure how complicated this is, but it would be huge.

Subscribing

Eric

mlncn’s picture

Another option is to tell users to use Firefox, which usually maintains form text information even after a back / forward move.

Equinger’s picture

I hear that and it's definitely a good thought.

If only I had control of my users! It is a business where they use ie7 for some reason and are change averse. I can't believe how difficult it is to get people to get browsers and particularly one that's not IE (particularly among older users). I'm sure this is a problem that many of us have.

Eric

kaakuu’s picture

subscribed

mlncn’s picture

Equinger: I agree that it would be best if the original request could be fulfilled, but i find even node autosave is not a surefire safeguard. Here is something that would give a bit of control over users:

http://drupal.org/project/dirtyforms

benjamin, agaric

(keywords: javascript warning when leaving text drupal)

sydneyshan’s picture

Just adding another vote for this feature. It's a great module - thanks for all the effort!

Crell’s picture

Version: master » 7.x-2.x-dev

The way the Drupal 7 version of this module works, it *should* be possible to do. I tried to keep such extension in mind when updating it. I do not have bandwidth to work on such a feature myself, but would accept patches.

I think what you'd need to do is add another branch to hook_form_alter for the comment form, and then introduce a branch of some sort to autosave_restore() for nodes vs. comments. (I don't think it can be done entirely generically.) The rest is just hooking up settings in the UI and such.

That said, the *only* reason to do this with an AHAH callback is for dynamic forms. For any form that doesn't change its structure in response to user input (the way "add more" fields work), this should be done using localStorage instead, completely client side. Comments, of course, are now in that first category in Drupal 7. Bah. :-)

czigor’s picture

Title: Autosave for comments » Autosave for any form
Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new7.88 KB

Attached patch creates a textarea on the admin/config/content/autosave form to add form_ids to apply autosave to.

The patch tampers with the html id of the autosaved form so it might brake some existing css.

I don't know what happens if there are several forms on the same page to autosave but it probably won't work.

czigor’s picture

StatusFileSize
new8.09 KB

This version removes the autosaved form on form submission.

Also, the patch from #2201317: autosave_node_presave() should be autosave_node_update() has been phased out.

czigor’s picture

StatusFileSize
new11.17 KB
new5.41 KB

Better and general handling of $form_state['build_info']['args']. (This is needed e.g. on entity forms.)

Also fixing autosaved form removal on form submit.

czigor’s picture

Assigned: Unassigned » czigor
Status: Needs review » Needs work

Previous patch works but has a huge security issue: the whole $form_state['build_info']['args'] array goes into the html. (Serialized, but still.)

So the proper way to do this is:
1. In autosave_form_alter() store $form_state['build_info']['args'] in the {autosaved_forms} db table in a new column (called 'args' for example).
2. In autosave_restore() $form_state['build_info']['args'] = $record->args;

czigor’s picture

StatusFileSize
new12.6 KB
new3.06 KB

Patch contains the suggested changes from the previous comment.

czigor’s picture

Status: Needs work » Needs review
StatusFileSize
new15.32 KB
new3.83 KB

Changes relative to previous patch:

  1. Introducing hook_autosave_prevent() to intervene the autosave process.
  2. Form arguments are not saved in a restore process.
czigor’s picture

StatusFileSize
new17.1 KB
new1.24 KB

Added an autosave.api.php file to document hook_autosave_prevent().

calebtr’s picture

Thanks for this patch. I've tested it a little with the weebform module and with a custom form and it works well.

czigor’s picture

Assigned: czigor » Unassigned
czigor’s picture

StatusFileSize
new17.56 KB
new1.11 KB

Make forms autosaved before the update work after the update.

czigor’s picture

  • czigor committed 035e881 on 7.x-2.x
    Issue #144596: Autosave for any form
    
czigor’s picture

Status: Needs review » Fixed
StatusFileSize
new17.87 KB
new3.22 KB

Fix hook_autosave_prevent_alter().
Committed.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

matt.rad’s picture

How do I get this to work for comments? I would like to try it out. Where can I find instructions for how to configure the module?

czigor’s picture

@matt.rad Go to admin/config/content/autosave and add the form id of the form you want to autosave.

matt.rad’s picture

Thanks a lot. It works perfectly.

For anyone else who might benefit be wondering, the module Devel Form Debug was an easy way to find form IDs.