Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
If the user successfully submits the form and then comes back later, autosave should not present the saved version of the form. Since their work on the form was not interrupted, it is confusing to see the autosaved values, as though their work had been interrupted.
This patch adds a submit handler to the form, so that on successful submit, the appropriate values are blown out of the autosaved_forms table.
Comment | File | Size | Author |
---|---|---|---|
#1 | autosave-prevent-race.diff | 24.65 KB | galaxor |
autosave-submithandle.diff | 2.63 KB | galaxor |
Comments
Comment #1
galaxor CreditAttribution: galaxor commentedSo I finally noticed that you already had a solution in place that was using hook_nodeapi('presave'). That is a good idea -- I switched my version to use presave instead of submit.
Still, I found that, even with my patch, there were still cases where this problem was cropping up. I have an alternative solution now, which seems to work better.
I added a 'status' column to the autosaved_forms table. When the form is first built and sent out, there will be no row in the autosaved_forms table. When the first autosave comes in, it'll add the row, and the status will be 'editing'. When new autosaves come in, they are saved only if the status column is not 'submitted'. Once the user successfully submits the form, the presave hook will change the status to 'submitted'. Any autosaves that come later will be ignored. When the user edits again, and that form is rebuilt, then we will delete from the table all the rows where status is submitted, and it matches the form_id, path, and user.
But if the user never edits the form again, we will have a bunch of stale 'submitted' rows in the database. So I made a cron hook that will delete the ones that are over an hour old.
Comment #2
chinita7 CreditAttribution: chinita7 commentedThanks for the patch.
I tried the dev version with patch #0 but didn't work for me. I would try #1 also but my site has problem with jquery UI module so not untill solve the problem with jquey UI.
Comment #3
liquidcms CreditAttribution: liquidcms commentedi am pretty sure this works without your patch; can you define a use case that shows it busted?
Comment #4
liquidcms CreditAttribution: liquidcms commentedComment #5
Crell CreditAttribution: Crell commented