Critical Error on Input using Field Ids [RESOLVED]

Critical Error when I indicated certain field IDs. The field IDs are not in order, a few larger numbers are at the top of the page.

This is the error that I received:
“There has been a critical error on this website.”
https://bit.ly/3x8zb64

I discovered the error on this code.
<input type=“checkbox” <?php echo in_array("Letter from School/ Institution", $form_data['field'][49])?'checked="checked"':'' ?>> 

However, removing just this code did not help. I have many similar codes below this one.

Here’s an example of same file but with input codes at the lower part of the page removed.
https://bit.ly/3PzkeQP

If I just copied the codes that worked and paste them below, there’s no error. Error occurs only when I entered the Field Ids and upload the file.

Is there a limit to how many input codes I can use in a page? Or is there a different explanation?

Appreciate your help.

Have you tried using debug mode and the ?data=1 query argument to check the contents of the $form_data to ensure the field you are trying to access is included?

I have not, will try it, thanks, Richard.

Hi Richard,

Following your advice, I managed to isolate and identify the error.

Though none of my checkboxes are required fields, if no option is selected on any of the checkboxes, I get a fatal error. My form contains many checkboxes.

Is there a setting that would allow users to not pick an option on a checkbox?

When I pick at least one option on the checkboxes, no error appears.

Thanks in advanced.

The easiest fix is to modify your custom template for Gravity PDF and cast your checkbox $form_data values to arrays in PHP:

<input type=“checkbox” <?php echo in_array( 'Letter from School/ Institution', (array) $form_data['field'][49], true ) ? 'checked="checked"': ''; ?> /> 

We use this technique in some of the examples shown in the Gravity PDF documentation: Form Data Array in Custom PDF Templates – Developers | Gravity PDF

Ideally, $form_data would always use an array for checkbox fields – even when empty. But for backwards compatibility reasons we can’t change this behaviour, and are locked into the use of an empty string when nothing is selected.

Thanks Jake, will try that. Appreciate it.

1 Like

Jake, thanks so much, it works. Brilliant.

2 Likes

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.