We have a multi-part form that allows users to attach files to their submissions. The attachments are limited to 10MB and document types only (e.g. PDF, DOCX etc).
When the file upload widget is placed on the first screen of the form, the user can proceed to the next screen even when the uploaded file fails validation. An error message is displayed on the next screen instead of preventing the user from going to the next screen.
While the file upload widget is placed on the last screen, the user can submit the form even when the uploaded file fails validation. An error message is displayed on the acknowledgement screen.
Comment | File | Size | Author |
---|---|---|---|
#10 | file-upload-error.png | 54.84 KB | steveworley |
#4 | b3.jpg | 47.73 KB | Dr Jason Guo |
#3 | b-2.jpg | 65.62 KB | Dr Jason Guo |
#3 | b-1.jpg | 52.2 KB | Dr Jason Guo |
Comments
Comment #2
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commented@Jason Guo
Can you please upload an example form that isolates the exact problem.
Comment #3
Dr Jason Guo CreditAttribution: Dr Jason Guo commented@jrockowitz
Thank you for the prompt reply!
Not quite sure if this is an issue only with multi-part form. Please see screenshots attached. The error does not stop users from going from step 1 to step 2.
Comment #4
Dr Jason Guo CreditAttribution: Dr Jason Guo commentedJust created a single-part simple test form with only one file field. If I submit the form before the Ajax uploading process completes, the form is still submitted and an error is displayed on the acknowledgement screen.
Comment #5
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commented@Jason Guo Can you create a simple 3 step form that duplicates the issue, export it, and upload it here.
Comment #6
Dr Jason Guo CreditAttribution: Dr Jason Guo commentedHi @jrockowitz
Thanks for this. Below is the simple three-page form using the last core 8.3.1 and webform 8.x-5.0-beta12.
If the user clicks next page before the file is uploaded via ajax to the server, they will still get to the second screen and still be able to submit the form in the end.
Below is the YAML export of the form:
Comment #7
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commented@Jason Guo Your example rocks!!! All I had to do was disable JavaScript and I could reproduce the validation issue.
The issue is that the ManagedFile element is using drupal_set_message() and not $form_state->getError().
This is a Drupal core issue and here is the ticket #2482783: File upload errors not set or shown correctly.
I am applied the latest patch from #2482783: File upload errors not set or shown correctly and it fixed the problem.
Comment #9
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedComment #10
steveworley CreditAttribution: steveworley at Acquia commentedHey @jrockowitz that patch fixed up the validation errors however the element seems to duplicate the ajax error. This doesn't seem to be a theme related issue as it happens with multiple themes and removing the error messages from the form element template doesn't prevent the alert.
I'm gonna continue digging into this error to see what I can find!
Comment #11
steveworley CreditAttribution: steveworley at Acquia commentedThis seems to be an issue with the FileManaged field. This this patch from https://www.drupal.org/node/2346893.
Applying the patch resolved the double validation error.
Comment #12
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commented@see #2346893: Duplicate AJAX wrapper around a file field