Hello,

We have encountered the following bug which forced us to deactivate the "Save as draft" feature on our webform. It happens with a file field. Even if the field is mandatory when :
- user goes to webform
- user uploads content in file field.
- user clicks save as draft.
- user clicks submit.

Then the file field is deleted.

Thanks for looking into it!

CommentFileSizeAuthor
#13 git-history.png131.04 KBquicksketch
#8 webform_file_draft.patch607 bytesquicksketch

Comments

vernond’s picture

For the clarity of my understanding of the problem, are you saying that after a user has browsed to the file to upload, and then clicks on Save as Draft that this causes the 'browsed to' filename to disappear from the file field? If so, then this possibly more of an HTTP limitation than a Webform issue as such.

jun’s picture

Hi Vernond,

Yes this is happening, but I think this limitation of HTML/HTTP is usually worked around by using things like hidden fields (which in the case of file fields require some extra work to keep track of the id of the uploaded file in Drupal, since there should be no reason to upload the file again).

In other words, yes it is a limitation, but to my knowledge it can be dealt with.

vernond’s picture

Whoops, I get a similar result when there's a validation error on the page as well (i.e. file browsing text disappears).

I agree, there must be some elegantly simple and monumentally effective way of dealing with this, but it falls well within my ignorance zone at this time. I'll see if I can dig up anything useful and post back here in a day or few.

quicksketch’s picture

Priority: Critical » Normal

Regarding the file being lost on a validation error, that's a separate issue over here: #322786: File attachment lost after validation error

Webform already has the ability to save a file via a hidden field and show the file name below the upload field in the event that you are viewing, editing, or resuming an existing submission. I'm guessing there's a bug in our handling of drafts that prevents this from working correctly.

mjwright’s picture

I've added a patch to my version (6.x-3.11) that seems to solve the problem. In components/file.inc at line 504, I changed this code:

    // Delete any previous files.
    if ($value['_old'] && ($existing = webform_get_file($value['_old']))) {
      file_delete($existing->filepath);
      db_query("DELETE FROM {files} WHERE fid = %d", $existing->fid);
    }

to this (don't delete the file if _old == _fid):

    // Delete any previous files.
    if ($value['_old'] && $value['_old'] != $value['_fid'] && ($existing = webform_get_file($value['_old']))) {
      file_delete($existing->filepath);
      db_query("DELETE FROM {files} WHERE fid = %d", $existing->fid);
    }
quicksketch’s picture

Ooo, nice one. Looks like it could work to me. I'll need to test this out to make sure there isn't some other code that should be solving this problem, but that change looks like a nice safety-catch in any case.

dunwich42’s picture

I could be getting this one as well.

quicksketch’s picture

Title: File deleted when submitting after saving as draft. » File deleted when submitting after saving as draft
Version: 6.x-3.9 » 6.x-3.12
Status: Active » Fixed
StatusFileSize
new607 bytes

I've tested this patch out in both Drupal 6 and Drupal 7 (which both had the problem) and it corrects both of them. Thanks mjwright! I've made it into a patch (attached here) and committed it to both branches of the Webform project.

Status: Fixed » Closed (fixed)

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

wheels394’s picture

Version: 6.x-3.12 » 6.x-3.14

I getting this same issue on 6x-3.14, attaching a file but losing it when save draft is used. What's weirder is the link to the file is showing up in the email but leads to a page not found and the file is not found in the database or results.

bayousoft’s picture

Version: 6.x-3.14 » 7.x-3.13
Status: Closed (fixed) » Active

I am finding that files are saved the first time you 'Save Draft' but are lost if you 'Save Draft' a second time without re-uploading.

quicksketch’s picture

Status: Active » Fixed

Sorry this fix was *not* in 3.12 or 3.13. I even committed my changes before 3.13 was released, but the 3.13 release wasn't made off of the "master" or 6.x-3.x branch, so the change wasn't included. This will be in the 3.15 versions for both D6 and D7.

quicksketch’s picture

StatusFileSize
new131.04 KB

Attached is a GitX screenshot of the changelog so you can see how this happened.

Status: Fixed » Closed (fixed)

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