Hello,

Thank you in advance for your support.
I use Drupal 7. Currently it is local with mamp on a mac.

Problem/Motivation

I want to use the functionalities of the module.
But I am blocked at the point where when I am editing the webform, and I click on the tab "Protected Downloads", it says "You need to attach private files to this webform".
I played around to be able to attach (I think) a private file. I did it in 2 ways, as you can see in the printscreens:
- by adding a file field in the form, then submitting the form with a file (so the file appeared in /sites/defaule/files/private/webform/)
- by adding a file in the edit tab of the form (so the file appeared in /sites/defaule/files/private/webform/)
Still, it says "You need to attach private files to this webform".

Errors

Working with that form, I also have continuously the following errors:

Notice: Undefined index: en in webform_protected_downloads_node_get_private_files() (line 452 of /Applications/MAMP/htdocs/smartpicker/sites/all/modules/webform_protected_downloads/webform_protected_downloads.module).
Warning: Invalid argument supplied for foreach() in webform_protected_downloads_node_get_private_files() (line 452 of /Applications/MAMP/htdocs/smartpicker/sites/all/modules/webform_protected_downloads/webform_protected_downloads.module).

Thank you very much for your help.
I don't know if it is a bug or if I am making mistakes.

Regards,

Jonathan

Comments

berliner’s picture

Hey, ok,
screen_shot_2.png is wrong.
screen_shot_3.png is closer I think, though I can't tell from the picture.

In general you need to add a private file field to the node type that is used as a webform (so by default the node type "webform"). Have you done this? To check this you can go to admin/structure/types/manage/webform/fields (assuming that webform is your node type), then edit the file field and check that under the "field settings" tab the Upload destination is set to private. If that option is not there go to admin/config/media/file-system and verify that your private filesystem path is correctly set up.

Hope that helps.

For the other errors I will look into that ...

berliner’s picture

Status: Active » Postponed (maintainer needs more info)

Did you encounter the mentioned notices using the latest dev? If not, could you upgrade please and verify that the problem persists?

Woodyjon’s picture

Hello sir,

Thank you for your reply.

Private files were set up as you mention. My private folder set up in admin/config/media/file-system is: sites/default/files/private.
So I think this seems correct.

I had the version 7.x-1.0-alpha1 which I downloaded yesterday. I just upgraded to the 7.x-1.x-dev version as you requested, and similar problems.
Except that now the error is at line 442 instead of 452.

Notice: Undefined index: en in webform_protected_downloads_node_get_private_files() (line 442 of /Applications/MAMP/htdocs/smartpicker/sites/all/modules/webform_protected_downloads/webform_protected_downloads.module).
Warning: Invalid argument supplied for foreach() in webform_protected_downloads_node_get_private_files() (line 442 of /Applications/MAMP/htdocs/smartpicker/sites/all/modules/webform_protected_downloads/webform_protected_downloads.module).

Woodyjon’s picture

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

StatusFileSize
new76.88 KB

Same problem here, also with the latest dev version. Once I have attached the private file, visiting the form gives me:

Notice: Undefined index: en in webform_protected_downloads_node_get_private_files() (line 442 of /Applications/MAMP/htdocs/sites/all/modules/webform_protected_downloads/webform_protected_downloads.module).
Warning: Invalid argument supplied for foreach() in webform_protected_downloads_node_get_private_files() (line 442 of /Applications/MAMP/htdocs/sites/all/modules/webform_protected_downloads/webform_protected_downloads.module).

see also screenshot attached.

I'm happy to provide more info. Let me know.

jim22’s picture

I'm having similar problems.

Drupal 7.7

I have created a private file field on webform content type. I have selected Private files as the Upload destination. I created a new webform and added 2 files to the Protected Files field.

I then go to the Protected Downloads tab and it says:
"Protected downloads are not available for the following reasons:
You need to attach private files to this webform."

Updated to latest dev release (Webform Protected Downloads 7.x-1.x-dev), and updated Webform 7.x-3.13 release, with no luck. Still getting the same "You need to attach private files to this webform."

My error message on form page is:

Notice: Undefined index: en in webform_protected_downloads_node_get_private_files() (line 442 of /var/www/vhosts/example.biz/httpdocs/sites/all/modules/webform_protected_downloads/webform_protected_downloads.module).
Warning: Invalid argument supplied for foreach() in webform_protected_downloads_node_get_private_files() (line 442 of /var/www/vhosts/example.biz/httpdocs/sites/all/modules/webform_protected_downloads/webform_protected_downloads.module).

Has anyone had any luck fixing this?

I really appreciate any help.

jschrab’s picture

I am coming across this same problem in 7.8. Looking at webform_protected_downloads_node_get_private_files() in webform_protected_downloads.module, I have the suspicion that files are being looked for in an inappropriate way. File fields are being looked for by way of key name with a prefix of "field_". I think that Webform changed quite a bit (or is this a D7 with Fields change?) since Webform Protected Downloads was written.

I think webform_protected_downloads_node_get_private_files() should be looking under:

$node->webform['components'][<iterate on array of fields>]['type']=='file' && $node->webform['components'][<iterate>]['extra']['private']==1

I'd pitch in on this, if I could have confirmation that my thinking is correct.
(Edit - using Webform 7.x-3.13)

berliner’s picture

For clarification, the basic functionality of this module is the following:
You have a content type (webform enabled) to which you add a private file field (this is a Fields API field, nothing to do with webform components). Using webform_protected_downloads you can than configure a specific node (webform) in a way that an attached private file (again, nothing to do with webform components) will be made accessible to a user only after he has submitted the webform. So without further regarding the code, your proposition to look for the files under webform components is not the solution to the described problem. Given the mentioned notices regarding undefined language indexes I'm more inclined to think that the problem is related to localization settings. At all those having problems with the D7 version of this module: Are you using the locale module?

Since I'm in holidays right now it's a bit difficult to work on this, but I will try.

opalu’s picture

Yep, exactly the same problems (drupal 7.8 / webform_protected_downloads-7.x-1.x-dev) and I'm using the locale module ...
but yet: happy holidays!
just disabled locale – everything fine (exept of the fact that I need locale).

jschrab’s picture

I'm not using Locale and have problems with the D7 version of Webform Protected Downloads.

Woodyjon’s picture

Indeed, by disabling Locale, it works!!
(at least for me)

getstarted’s picture

I also have the same problem. I am on Dev version of the module with core 7.7 with local module never enabled.

perisdr’s picture

Same problem here

Notice: Undefined index: en in webform_protected_downloads_node_get_private_files() (line 442 of C:\xampp\htdocs\BizTech\sites\all\modules\webform_protected_downloads\webform_protected_downloads.module).
Warning: Invalid argument supplied for foreach() in webform_protected_downloads_node_get_private_files() (line 442 of C:\xampp\htdocs\BizTech\sites\all\modules\webform_protected_downloads\webform_protected_downloads.module).

Though disabling the Local module didn't change anything
Running the dev version.

berliner’s picture

Status: Active » Needs review
StatusFileSize
new2.21 KB

Since I couldn't reproduce the problem I went directly into the database and provoked the problem by manually switching the nodes language to english (was UND before in my case) but keeping the attached files languages as UND. That way I saw the described message next time I went to the configuration screen. So the reason for the problem is different languages of node and file fields. This can happen in several ways:
1. Having modules that allow language specifications for nodes and fields and uploading files in a language different to the node language
2. Having had modules that ... (this is because deactivating locale modules doesn't automatically reset the nodes or files language)

The current assumption for wpd is, that files must have the same language as the node. In the attached patch I changed that so that simply all attached files of a node can be used, independently of their language settings (if any are given).

Please test this patch against the current dev version. If it solves your problem I would like to get this rolled into an alpha2 release as soon as possible.

And sorry for the monstrous delay, but I have been away for quite some time and only returned for christmas holidays.

Frederic wbase’s picture

The path of #14 works perfect with locale enabled, thanks for your hard work berliner!

grts

frederic

perisdr’s picture

Patch seems to be working fine. Locale is enabled so no problem there.
Thanks berliner

perisdr’s picture

After patching I am getting some warnings when trying to edit my webform

Notice: Undefined index: #after_build in webform_protected_downloads_form_alter() (line 834 of C:\xampp\htdocs\BizTech\sites\all\modules\webform_protected_downloads\webform_protected_downloads.module).
Warning: in_array() expects parameter 2 to be array, null given in webform_protected_downloads_form_alter() (line 834 of C:\xampp\htdocs\BizTech\sites\all\modules\webform_protected_downloads\webform_protected_downloads.module).
Notice: Undefined index: #field_name in webform_protected_downloads_file_widget_after_build() (line 900 of C:\xampp\htdocs\BizTech\sites\all\modules\webform_protected_downloads\webform_protected_downloads.module).
Notice: Undefined index: #field_parents in field_widget_field() (line 543 of C:\xampp\htdocs\BizTech\modules\field\field.form.inc).
Notice: Undefined index: #field_name in field_widget_field() (line 543 of C:\xampp\htdocs\BizTech\modules\field\field.form.inc).
Notice: Undefined index: #language in field_widget_field() (line 543 of C:\xampp\htdocs\BizTech\modules\field\field.form.inc).

Any ideas?

berliner’s picture

Hi perisdr,

thanks for reporting. I found the problem and some more. I tried to address them all in a new patch. Please note, that the patch in #14 is included in this one, so you need to unpatch it first or to get the current dev version fresh from the repository before applying this patch.

Included in this patch should be the following fixes:

  • The original problem of this issue
  • Correct display of attached private files that are not protected if multiple files have been uploaded
  • Support for field type image
  • Correct check for a webform node type on the node edit form
  • Correct access to the file field object of a protected file on the node edit form (this bug has been the cause of the reported warnings from #17)
  • Disabling of the removal button for protected files in the node edit form

Thanks for testing and feedback!

berliner’s picture

please try this patch instead of the previous

perisdr’s picture

Yes the patch seems to take care the warnings when I go editing an existing webform. I will be playing around a little more so if anything more comes up I 'll give you a heads up. So far the log is clear of any webform entries. Hope to remain like this :)

Thanks for the fast fix

feuerste’s picture

Component: Miscellaneous » Code

I had the same problems described above (using locale as well). With patch #3 everything works like a charm. I hope you include it soon into the downloadable version.
Thanks for the great work.

berliner’s picture

Status: Needs review » Fixed

Thanks for the feedback. The patch has been pushed to the dev branch and an alpha2-release has just been created.

Status: Fixed » Closed (fixed)

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