Hi,

I have installed webform 7.x-4.1 and used the file component.

If I add a mandatory private file component to a webform and I try to submit as anonymous user:

A) If I click the upload button the file upload field gets cleared out and it gives me an error
B) If I submit without pressing the upload button it works fine.

There is a smilar issue in https://www.drupal.org/node/1461098#comment-9333921 although mine is with the version 4 and I don't have other modules like locale or webform validation turned on.

As suggested I opened a new issue specifically for this version.

Thanks,

Comments

DanChadwick’s picture

Priority: Major » Normal

What error is given?

Is this perhaps related to #2339109: Multiple file uploads don't work with Drupal cache enabled?

kyuubi’s picture

Hi,

This happens even with only one file and caching is turned off.

The error is basically the mandatory field error:

"File field is required."

Remember this only happens when you use the upload button and then submit. If you just submit the form without using the upload button it works fine.

kyuubi’s picture

Hi,

Can you also explain why you mark this as normal?

This impacts greatly the ability to use mandatory private files and since we can't just use it as public (security implications) this would definitely be marked as major.

DanChadwick’s picture

Normal because it affects one small combination of factors.

Patches are welcome, regardless of priority. :)

kyuubi’s picture

Hi Dan,

Any chance a maintainer from the module can have a look at this?

Webform is a big module :P

I try nonetheless..

DanChadwick’s picture

Yes, webform is a big module and I am not particularly familiar with the managed file upload process. However in googling on the topic, it appears that the upload button is not needed (which I didn't know). The file is uploaded when you submit, apparently. So one option would be to hide the upload button with CSS or remove it in a #process function.

kyuubi’s picture

Hi Dan,

Thanks for your reply.

I guess that can work as a temporary solution, until further information is discovered on this problem.

Cheers,

VBN’s picture

Same issue in 3.19 and 3.21

-Subscribing-

ben600324’s picture

I got the same issue. Anyone can help?

rkent_87’s picture

Same issue here too

littlepixiez’s picture

I hid the upload field with CSS for now as well... How annoying.

DanChadwick’s picture

Status: Active » Closed (cannot reproduce)

I just tried this with Firefox on Windows. I gave anonymous users the access own webforms permission. I created a webform containing a required file component which is store in the private file system. I did NOT check the "Private" checkbox, which would should the field only to those with access all webform results permission.

I then tested with an anonymous browser session and could choose the file, click Upload, get the revised link, and then click Submit. I could also click the link and see the file.

I tested with Windows 7 and Chrom Version 40.0.2214.93 m. Also works with Firefox 35.0.1.

Please reopen with detailed reproduction instructions, particularly if you can reproduce this on more than one browser / computer. Also, please re-test with the latest webform 7.x-4.x.

theMusician’s picture

Version: 7.x-4.1 » 7.x-4.2
Status: Closed (cannot reproduce) » Active

I am seeing this issue as well on Webforms 7.x-4.2. It may have been present earlier but my users had not raised the issue. I have reports of users experiencing this on IE 11 as well as personal experience on Firefox for OSX and Chrome for Windows.

I have a required file component set to store the uploaded file in the private filesystem. I did NOT check the private box either. This particular form has multiple required elements but only one file component.

The Upload button does allow a user to attach the file to the form, but when they submit the form an error is returned stating that the field is required. If I do not click the Upload button and just the Submit button the form is submitted successfully.

DanChadwick’s picture

Status: Active » Postponed (maintainer needs more info)

@theMusician -- can you reproduce it? I could not, including on Chrome for Windows. If you can reproduce it, then you can debug it to see what's going on.

DanChadwick’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)

It's not that I don't think there's an issue. It's that no one has been able to provide reliable Steps To Reproduce.

jesss’s picture

Status: Closed (cannot reproduce) » Active

Steps to reproduce:

Create a webform with a file field.
* Upload destination: Private
* Validation: Required

Fill out the form as an anonymous user.
* Select your file.
* Click the Upload button.
* Submit the form, get the "File field required" error.

Try again (still as anonymous).
* Select your file.
* Do NOT click the Upload button.
* Submit the form, all is well.

This behavior is what I'm seeing in Chrome, Internet Explorer, and Firefox.

DanChadwick’s picture

@jesss - That's what I did in #12, and it worked for me. So what's different?

Cookies disabled?

Can you reproduce this with only a single component on the webform (the mandatory file)? There is a know core bug with uploading more than one file for anonymous users. It relates to the regeneration of the form_build_id during the ajax request to upload the file. The solution is to hide the upload button with CSS.

Or can you start with a fresh drupal installation, install webform only, set up the private file system, create the webform, log out, and upload it properly?

jesss’s picture

I've recreated the issue on a clean install using simplytest.me. The error appears when the File Entity module is also installed.

So, steps to reproduce (edited):

Install and enable Webform and File Entity

Create a webform with a single file field.
* Upload destination: Private
* Validation: Required

Fill out the form as an anonymous user.
* Select your file.
* Click the Upload button.
* Submit the form, get the "File field required" error.

Try again (still as anonymous).
* Select your file.
* Do NOT click the Upload button.
* Submit the form, all is well.

DanChadwick’s picture

Project: Webform » File Entity (fieldable files)
Version: 7.x-4.2 » 7.x-2.0-beta1

Since File Entity modifies the core file functionality, I'd suggest that this issue should be moved to the file entity issue queue. It may get bounced back here.

This is a bit of an awkward situation. When two modules don't interact well together, whose responsibility is it to diagnose the issue and create patch(es)? Alas, @jesss, it may be yours.

Dave Reid’s picture

Status: Active » Postponed (maintainer needs more info)

Was the anonymous user assigned the 'download own private files' permission with File Entity enabled?

jesss’s picture

The issue appears on a clean install -- I hadn't touched the permissions page. The only File Entity permission the anonymous user has is 'View files.'

After giving the anonymous user the 'Download own private files' permission and clearing the cache, I still get the error message if I hit the Upload button before submitting the form as an anonymous user.

jesss’s picture

Status: Postponed (maintainer needs more info) » Active
Rom Soul’s picture

Same problem here...

So this would be an interference between two modules :
- Webform
- Entity reference
(* How come these two can interfere ?... *)

The thing is I need them both !
Hope a solution appears soon.
In the meanwhile, I am going to hide the "upload" button via CSS, but this is not a very glorious way out ...

kyuubi’s picture

Hey guys,

Still having this issue.

Is anyone close to understanding what causes this?

It basically makes using media with file entity very dangerous and both are very established modules.

Is there any clue to the cause?

knalstaaf’s picture

Glad I'm not the only one who has this issue in Webform. (I'm not using the File Entity module BTW, but the Bootstrap theme)

Any news on this?

Yeenaru’s picture

My instance: Drupal 7.43, Webform 7.x-4.12
My issue: When submitting a form as an anonymous user with a file uploaded to a private component, the submission fails when the upload button is clicked if the component is required.

My findings:
After some debugging this is my understanding of the issue.
The issue appears to occurs when the form is built and the file module returns a value of 0 for the file fid due to user access rights.

When Webform processes the form it calls form builder and tries to generate the $form_state['values'] array, because the upload button was clicked this creates a temporary file managed record for the uploaded file.
Once it gets to the point of getting the file value in the file.module, file_managed_file_value function gets called. At this point the file module is checking access permissions for the current user using the file path, anonymous users by default do not have access to private files, additionally anonymous users cannot access temporary files as there is no way to determine file ownership. As the user is denied access to the file this function ultimately returns a fid of 0.
When the webform goes to validate, the file fid in form_state['values'] is 0 and we get the error.
If the upload button wasn't clicked then the file module seems to recognise the file as a brand new file and saves it straight away as there is no file managed record to check access rights against.
Unfortunately there doesn't appear to be an easy solution, patching is difficult as at this point i'm uncertain as to who's responsible for managing this situation, webform or the file module.

If anyone could clear that up that would be great and allow people to start applying patches.
(the temporary fix i've gone with is also to remove the upload button with ccs as others have already suggested)

jackalope’s picture

I'm seeing this behavior when using Chrome/Linux and Chromium/Linux. I've observed this using both File Entity 7.x-1.5 and 7.x-2.0-beta2 and both Webform 7.x-3.24 and 7.x-4.12.

This problem does not occur for me in Firefox/Linux.

I'm not sure whether this is relevant, but in Opera, the file upload fails entirely with this message in the JavaScript console: Unhandled Error: 'window['_' + this.id]' is not a function. I see no such error in Chrome or Chromium; just the problem where if I click the Upload button for a mandatory file, then submit the webform, I get the "field is required" error.

Happy to contribute what I can to tracking this down (though Yeenaru seems to have a pretty good lead in the comment above!)

nategasser’s picture

Not sure if this is the same issue since it's cited as a regression in D7.43, however, this patch solved the problem for me:
https://www.drupal.org/node/2678822#comment-10926613

prashant.kabade’s picture

Must Read this before implementing this File upload for Anonymous user .

https://www.drupal.org/psa-2016-003

prashant.kabade’s picture

Must Read this before implementing this File upload for Anonymous user .

https://www.drupal.org/psa-2016-003

jesse.voogt’s picture

For me, I just upgraded from beta1 to beta3 after upgrading from drupal core 7.44 to 7.51 (7.5 had incorporated a related patch) - this combination fixed the issue I was having. In my estimation, the issue I was experiencing was that anonymous users couldn't upload to the private file system unless they (a) filled out the form perfectly the first time, avoiding validation errors and (b) did NOT hit the upload button.

loopy1492’s picture

Also "fixed" this by hiding the upload button via CSS.