Fields with multiple values simply show "Array" in TCPDF output

coughlin 27 Jun, 2019
We are building a CFv6 form with a TCPDF output. This form has many fields which may be left blank (such as optional fields, or entire sections of conditional fields), so naturally we need to exclude the blank fields from the output.

The only way we have found to achieve this is by creating PHP actions before the TCPDF, which create string variables based on only non-empty values.

This works great, except for any fields with multiple values/arrays. In the PDF output, the string only displays "Array."

What's interesting is that we CAN get the values to display like this: ["value1","value2","value3"] if we display it as a separate PHP variable outside of the string. However, this defeats the purpose of being able to skip empty values.

Please help! If you can take a look and let us know if we are doing something wrong with the PHP, or if there is an easier way to accomplish returning only non-empty values to the PDF, please advise!

This is private content

healyhatman 27 Jun, 2019
So if there's an array of values you will want to either loop through and print them out as required, or implode them.

Better way of building text for a TCPDF action is using Custom Code block instead of PHP block, set to return as var. Then you can mix HTML and PHP as required.
coughlin 28 Jun, 2019
I am not sure the best way to loop. I was looking for better documentation on that in the forums with little success. Are you talking about creating a for/next loop with php code and putting that in the custom code block or using the loop event?

I will look into the Custom Code block, but am not sure how it would save me anything. I have checked the manual and I see that I can add php code in the custom code block with the php tag, but in the end wont that just be a lot of extra characters in the code?
healyhatman 28 Jun, 2019
Well you only need the PHP tags when you specifically need to use PHP and the rest of the time you can use standard HTML and CF shortcodes so it's a lot easier to build and maintain
coughlin 01 Jul, 2019
Right, but as previously explained, we are having to use PHP for the majority of the form fields so that the PDF does not include all the fields with empty values. Is there any other way to do that?
healyhatman 01 Jul, 2019
yes custom code block can mix PHP inside <?PHP tags ?> and HTML+shortcodes outside the tags
coughlin 02 Jul, 2019
So, I have an array that I do NOT want to be shown in the PDF if the values are empty. I can accomplish this. However, when there ARE values to be shown, it returns "Array" instead of the values.

If using a loop or implosion to fix this is the only solution, can you provide an example of what that looks like?
healyhatman 02 Jul, 2019
Answer
echo implode($glue, $array);

https://www.php.net/manual/en/function.implode.php

foreach($array as $row) {
echo $row;
}
https://www.php.net/manual/en/control-structures.foreach.php
coughlin 03 Jul, 2019
Thanks. I was able to use the implode feature within the php code to get the values that I needed. I appreciate the help.
This topic is locked and no more replies can be posted.

VPS & Email Hosting 20% discount
hostinger