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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Jason Guo created an issue. See original summary.

jrockowitz’s picture

@Jason Guo

Can you please upload an example form that isolates the exact problem.

Dr Jason Guo’s picture

FileSize
52.2 KB
65.62 KB

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

Dr Jason Guo’s picture

FileSize
47.73 KB

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

jrockowitz’s picture

@Jason Guo Can you create a simple 3 step form that duplicates the issue, export it, and upload it here.

Dr Jason Guo’s picture

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

page_one:
  '#type': wizard_page
  '#title': 'Page one'
  document_name:
    '#type': textfield
    '#title': 'Document name'
  upload_document:
    '#type': document_file
    '#title': 'Upload document'
    '#max_filesize': '1'
    '#file_extensions': 'pdf doc docx'
page_two:
  '#type': wizard_page
  '#title': 'Page two'
  phone_number:
    '#type': textfield
    '#title': 'Phone number'
page_three:
  '#type': wizard_page
  '#title': 'Page three'
  email:
    '#type': email
    '#title': Email
jrockowitz’s picture

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

  • jrockowitz committed 915d3e7 on 8.x-5.x
    Issue #2874490 by Jason Guo: Failed file field type/size validation does...
jrockowitz’s picture

Status: Active » Postponed
steveworley’s picture

FileSize
54.84 KB

Hey @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!

steveworley’s picture

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

jrockowitz’s picture

Status: Postponed » Closed (won't fix)