I am debugging a form in which I observe the following: I click "next page", but everything on the following page is hidden due to conditionals. Because of #1781490: Conditional fields can cause form to submit unexpectedly, the form would submit, except that the submission is stopped by Webform's unique validation. So, it does not submit and the validation error appears, but the email gets sent anyway. As well, if I then edit the data entered into the form and click "next page" again, the same thing happens, but it is as if I did not make any edits, that is, the unique validation fails, the error message shows the first value I entered, and the first value appears in the form when it redisplays.
I do not yet know how to reproduce this and I am working on that.
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | webform-validation_fail_submit-2313521-9.patch | 1.5 KB | danchadwick |
| #7 | webform-validation_fail_save-2313521-7.patch | 1.11 KB | liam morland |
Comments
Comment #1
liam morlandThis seems to be caused by a combination of conditionals and forms with Submission access to authenticated users only. Problem observed in latest development version. Still investigating.
Comment #2
danchadwick commentedLiam, I suspect that there are problems when the last page of the form is either empty (component list ends in a page break, for which there is an issue, or hidden due to conditionals).
It is rather a mess, but I think we need the equivalent of "This page left intentionally blank." -- some sort of message saying that all that's left to do is submit the form.
Comment #3
liam morlandYes, that is what I was advocating in #1781490: Conditional fields can cause form to submit unexpectedly. Perhaps the preview page should always show up in these cases.
Comment #4
liam morlandTry this: Create a webform with 2 components separated by a page break. Create a conditional which only shows the page break if a given value is put in the first component. Set that first component to be required. Set the form to save draft when validation fails. Click "next page" with the first component empty. The validation failure message will show up, but the form with submit. Keep clicking "next page" and the form will submit every second click.
Comment #5
liam morlandComment #6
liam morlandI have not yet been able to reproduce on my clean install the email being sent without the form submitting, but that only happened in the context of the above problem, so it would probably be fixed if the issue described in #4 was fixed. (Still, something is wrong if email sending is decoupled from form submit.)
Comment #7
liam morlandOK, I think I have uncovered a bug that would have been introduced in #2284595: Save as draft when form fails validation. The attached patch seems to be fixing the problem I have been having. Please have a look and let me know if it makes sense from the perspective of someone who knows much more about the Webform submit process than I do.
Comment #8
danchadwick commented@Liam - Thanks for your excellent work on this. I set up your scenario and stepped through the code.
First, it may not be obvious that the call to each submission handler is being done from the validation handler. What it does to the form and form_state doesn't matter; only the side effect matter. The goal is to cause the desired side effects (e.g. creating or saving the draft, setting the cookies for the draft, etc) and avoid undesired side effects (sending the mail, setting messages).
Your scenario is an example of the greater problems that we currently have where the last page submits. If the submission handlers didn't think you were all done, it wouldn't submit the form. In specific, it is important that $form_state['save_draft'] be TRUE and at the bottom of webform_client_form_pages it is set to:
Since the auto-save op isn't checked and since it (mistakenly) thinks that the form is complete, it submits the form, sending the e-mail and setting the message.
I do suspect that this bug would go away once we correct the definition of when a form is complete, but it certainly can and should be prevented.
We can fix the bug either as you've done, but ensuring that $form_state['webform_completed'] is FALSE in the test above, or by checking for the special __AUTOSAVE__ op. The intention of the line above is to say that the submission is a draft if a) it's a draft by virtue of clicking Save Draft or b) draft are saved between pages and there are more pages.
Therefore to keep the code most similar to Save Draft, I think we should exclude auto_save from the big multi-page-check IF (as your patch does) and add it to the explicit test for setting $form_state['save draft'].
I'll try this and if it looks good, post a patch later. This should go into 7.x-4.0.
Comment #9
danchadwick commentedLiam -- Please try this patch to see if it works equally well as yours.
This leave the problem of the form submitting unexpected when there is no error, a different issue.
Comment #10
danchadwick commentedCommitted to 7.x-4.x and 8.x.
Comment #12
liam morlandLooks good! I will test it on Tuesday when I am back at my desk.
Comment #13
liam morlandProblem is fixed by this change. Thanks.