I have a webform with multiple pages, set to save draft on pressing prev/next (or the save draft btn). The form has many fields including 3 mandatory file upload fields on one page.

Normally when a person starts the form and then saves, logs out, and comes back later to continue, they are returning to the same instance of their form - so you only ever see 1 draft per drupal account on the results screen.

What's happening with out form is that each time the attachments are changed a new copy of the draft is saved for that user, so you end up with multiple drafts for the same Drupal user in the results list.

The user is always directed to the most recently saved version of their form when they log in and go to the webform, so it's not a huge problem - but makes the results tab messy and can definitely be classed as a bug.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

kmcculloch’s picture

I am noticing this behavior as well. I replicated my webform in a clean Drupal 7.14 installation to test. Nothing is enabled except standard core modules and webform.

Form setup details:

6 page form
Mandatory textarea fields on pages 1-4 and 6
Mandatory file upload on page 5
file type limited to "pdf"
"save draft" button enabled
save as draft between pages enabled
form limited to 1 submission per user ever
form access limited to authenticated users

Testing process:

I do a test submission, moving through the form step by step, entering sample text in each textarea. I browse for a "pdf" and upload it into the mandatory file field. I do not use the "Save Draft" or the "Previous Page" buttons. I submit the form.

Expected result:

A single completed submission including all textarea values and a link to the uploaded file.

Actual result:

A single draft submission including textarea values for pages 1-4. (Submission ID is #1.)
A single completed submission including all textarea values and a link to the uploaded file. (Submission ID is #2.)

Incidentally, I checked the files/webform directory and can confirm that the file was uploaded once and only once.

grahamC’s picture

Yeah, this fails equally well with only:

Textfield component
Pagebreak
File component

Save draft between pages enabled.

Add a file and click "Upload", then click Submit.

grahamC’s picture

  1. During the ajax request, the sid is being removed from $form_state['values'] by overly specific form validation. (#limit_validation_errors is in effect).
  2. The form is being rebuilt, and with no sid in $form_state['values'], $form['details']['sid'] ends up defaulting to #value => ''.
  3. The rebuilt form with missing sid is set in the form cache.
  4. When the form is submitted, the correct sid is still available in $form_state['input'], but this isn't copied to $form_state['values'] because the $form['details']['sid'] (from cache) already has a #value set.

Can someone wiser think of a way around this situation?

grahamC’s picture

Status: Active » Needs work
FileSize
619 bytes

Attached patch targets part 4. of my description in comment #3.

It seems to make the issue as stated go away, but looks like there are similar issues with at least the uid here, possibly others.

(admin edits user's submission, uploads a file, re-submits - submission may well now belong to admin because of lost uid)

manimejia’s picture

We are also experiencing this exact problem.

grahamC’s picture

Status: Needs work » Needs review

For the record, I've still never actually _seen_ a problem in Webform with anything but the sid (though this kind of bug exists in several other modules)

We've been using my patch from #4 in production successfully.

quicksketch’s picture

Hi guys, thanks for your research on this issue. I'm guessing this issue continues to affect even the latest versions of Webform (4.x), because there haven't been any other major changes around this area.

During the ajax request, the sid is being removed from $form_state['values'] by overly specific form validation. (#limit_validation_errors is in effect).

I wonder if we could adjust the #limit_validation_errors property to simply include the 'details' portion of the form? But I'm not quite understanding why the file validation would be causing this problem to begin with. Like you say, this would cause problems in a lot of modules other than just Webform. Is there a core issue that you know of tracking this problem?

quicksketch’s picture

Oh! I just realized what's going on here. If that patch works, then it seems like we could just change the empty string to NULL:

     $form['details']['sid'] = array(
       '#type' => 'hidden',
-      '#value' => isset($submission->sid) ? $submission->sid : '',
+      '#value' => isset($submission->sid) ? $submission->sid : NULL,
     );

This makes it nearly same thing as your patch. And 'sid' wouldn't have a value so it wouldn't get cached (I think).

quicksketch’s picture

Status: Needs review » Fixed
FileSize
423 bytes

Assuming this is correct, this patch should fix the problem. Since it should have a minimal impact on the rest of Webform, I've committed it. Please reopen if this has not solve the problem. Committed to 7.x-3.x and 7.x-4.x branches. Thanks for the sleuthing guys!

Status: Fixed » Closed (fixed)

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

szume’s picture

Version: 7.x-3.18 » 7.x-4.4
Issue summary: View changes
Status: Closed (fixed) » Active

I had a same issue in 7.x-4.2. I upgraded to version 4.4, but the issue is still have.

Update:

Comment #4 patch worked for me intsead of the official(#9) solution.

szume’s picture

Status: Active » Closed (fixed)
DanChadwick’s picture

@szume -- Are you saying you had to patch 4.4 to get it to work? If so, can you provide detailed instructions to reproduce the issue?

pete80’s picture

I am having the same issue with 7.x-4.10

To recreate:
Create a webforms with three pages
Add a file field to the second page
In "Form settings" select "Automatically save as draft between pages and when there are validation errors"
Fill in the form, when you press the first next page a submission is created, then upload and image on the second page, when you press next page again a new submission is created.

I have re rolled the patch from #4 against the latest dev branch, which fixes the issue for me

DanChadwick’s picture

Re #14. Try the latest dev without your patch. There was an issue caused by the ajax call when you click the upload button.

Otherwise, please open a new issue.