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.

Comments

liam morland’s picture

Version: 7.x-4.0-rc4 » 7.x-4.x-dev

This 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.

danchadwick’s picture

Liam, 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.

liam morland’s picture

Yes, 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.

liam morland’s picture

Try 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.

liam morland’s picture

liam morland’s picture

Title: E-mail sent, but form does not submit » Form submits even if validation fails

I 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.)

liam morland’s picture

Status: Active » Needs review
StatusFileSize
new1.11 KB

OK, 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.

danchadwick’s picture

@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:

  $form_state['save_draft'] = $form_state['values']['op'] == $draft_op || ($node->webform['auto_save'] && !$form_state['webform_completed'] && user_is_logged_in());

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.

danchadwick’s picture

Liam -- 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.

danchadwick’s picture

Status: Needs review » Fixed

Committed to 7.x-4.x and 8.x.

  • DanChadwick committed 175f14e on 7.x-4.x
    Issue #2313521 by Liam Morland: Fixed webform submits with failed...
  • DanChadwick committed 095be1d on 8.x-4.x
    Issue #2313521 by Liam Morland: Fixed webform submits with failed...
liam morland’s picture

Looks good! I will test it on Tuesday when I am back at my desk.

liam morland’s picture

Problem is fixed by this change. Thanks.

Status: Fixed » Closed (fixed)

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