Research-IT-Swiss-TPH / redcap-pdf-injector

PDF Injector is a REDCap module that enables you to populate fillable PDFs with record data from variables.
https://research-it-swiss-tph.github.io/redcap-pdf-injector/
MIT License
7 stars 7 forks source link

Uncaught TypeError: array_filter(): Argument #1 ($array) must be of type array #45

Open tertek opened 1 month ago

tertek commented 1 month ago

Issue reported by user on REDCap Community:

"I've encountered an error with the module I was hoping you could help with.

The issue occurs when trying to open the injected PDF using the action tag field. Also, when trying to open the pdf from the record home page nothing happens.

REDCap Version 14.0.33 PDF Injector - v3.1.0

REDCap crashed due to an unexpected PHP fatal error!

Error message: Uncaught TypeError: array_filter(): Argument #1 ($array) must be of type array, null given in modules\pdf_injector_v3.1.0\pdfInjector.php:314 Stack trace: #0 modules\pdf_injector_v3.1.0\pdfInjector.php(314): array_filter() #1 modules\pdf_injector_v3.1.0\preview.php(13): STPH\pdfInjector\pdfInjector->renderInjection() #2 redcap_v14.0.33\ExternalModules\index.php(146): require('...') #3 {main} thrown File: modules\pdf_injector_v3.1.0\pdfInjector.php Line: 314"

Source:

https://redcap.vumc.org/community/post.php?id=108925&comment=235866

tertek commented 1 month ago

Could you please explain what you mean by "using the action tag field" ?

tertek commented 1 month ago

Also please report your PHP version.

BHDIdata commented 1 month ago

Hello, David here, I will provide as much as I can:

PHP 8.1.3 (Windows OS)

This field when clicking on the button shows the original error:

685 | [gp_letter_inject] | Gp Letter Injection Test | descriptiveField Annotation: @PDFI='260472' -- | -- | -- | --

image

Clicking on the thumbnail below does not do anything: image

I have cloned the project and the cloned version works fine, with all pdf injections running, but in the original project (which was created 2023-11-28) it does not work.

tertek commented 1 month ago

Hi @BHDIdata The error is referring to line 314 where user permissions are being checked: https://github.com/Research-IT-Swiss-TPH/redcap-pdf-injector/blob/6a249ba24afeb9cc1ad271bfa3721f1455ce4d0c/pdfInjector.php#L312-L314

Could you please compare the user's rights that you encounter the error with, and report back if there is anything different regarding access on that specific project and form?

It is a bug for sure! Thanks :)

tertek commented 1 month ago

@BHDIdata The second issue with the thumbnail seems to be a problem in JavaScript. Could you please open the Developer Tools of your browser and check if there are any red messages (errors?)

Please also ensure, that in Module settings the option "Debug" is enabled.

image

BHDIdata commented 1 month ago

Ahh interesting, I realised that my admin account was not actually added to the permissions of the project, since as an admin I rarely need to be. Adding my admin account to the project with permissions has allowed me to access the injected pdf using the action tag button inside the instrument.

However, the javascript button and thumbnail still do not activate

I've refreshed the page and opened the console, this error appears when clicking the button:

image

record_home.php?pid=1093&arm=1&id=ELF_001:128
Uncaught ReferenceError: ELF_001 is not defined at HTMLAnchorElement.onclick (record_home.php?pid=1093&arm=1&id=ELF_001:128:220)

In this project, "ELF_001" is the name of the first record, implemented by a module "Custom Record Auto-numbering - v1.0.6" by Luke Stevens (Murdoch Children's Research Institute) The cloned project does not have this, as I had not thought it necessary for testing, but perhaps that is the cause.