Problem loading data into tcpdf

How to fix missing data in a TCPDF generated from a ChronoForms form.

Overview

The issue occurs because the PHP code used to fetch and display data in the form does not work correctly within the TCPDF action, often due to incorrect syntax for accessing form data.
First, ensure you use the correct array syntax to access form data. Then, test the PDF generation with static HTML to isolate the problem. If the data is complex, consider moving the table generation logic to a Custom Code action to build the content before passing it to the TCPDF.

Answered
st stikki 25 Jan, 2017
Hi

I have a form, which uses php to display the records I want from a database and this is working well. I added a TCPDF action to the form and copied the code from the form into the TCPDF window, but it doesnt work here - none of the data is being displayed. The table headers are being displayed, so I think the problem is with my method of supplying the data.


I would be very grateful if someone could tell me what I'm doing wrong and how to fix it so it works!


<table class="table" style="width:100%;font-size:12pt;">
<tr>
<th>Parent first name</th>
<th>Parent last name</th>
<th>Contact1</th>
<th>Phone1</th>
<th>Contact 2</th>
<th>Phone1</th>
<th>Child first name</th>
<th>Child last name</th>
<th>DOB</th>
<th>Medical</th>
<th>Notes</th>
</tr>
<?php
$date=$form->data('camp_date');
foreach($form->data['day'] as $detail):
if (in_array($date, $detail) AND $detail['deleted']!="Yes") {
?>

<tr>
<td>{parent_first_name}</td>
<td><?php echo $detail['parent_last_name']; ?></td>
<td><?php echo $detail['contact1_name']; ?></td>
<td><?php echo $detail['contact1_phone']; ?></td>
<td><?php echo $detail['contact2_name']; ?></td>
<td><?php echo $detail['contact2_phone']; ?></td>
<td><?php echo $detail['child1_first_name']; ?></td>
<td><?php echo $detail['child1_last_name']; ?></td>
<td><?php echo $detail['child1_dob']; ?></td>
<td><?php echo $detail['child1_medical']; ?></td>
<td><?php echo $detail['child1_notes']; ?></td>
</tr>


Thanks
Max_admin Max_admin 25 Jan, 2017
Hi stikki,

This is the complete code ? the foreach and the if statements are not closed, and the table too.

Best regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
st stikki 25 Jan, 2017
Hi Max

Thanks for the reply - no not the complete code - I've put that below. It works on the form, but not on the TCPDF.
Date: {camp_date}
Session: {session}
<br /><br />

<table class="table table-condensed" style="width:100%;font-size:12pt;">
<tr>
<th>Parent first name</th>
<th>Parent last name</th>
<th>Contact1</th>
<th>Phone1</th>
<th>Contact 2</th>
<th>Phone1</th>
<th>Child first name</th>
<th>Child last name</th>
<th>DOB</th>
<th style="width:15%">Medical</th>
<th>Notes</th>
</tr>
<?php
$date=$form->data('camp_date');
foreach($form->data['day'] as $detail):
if (in_array($date, $detail) AND $detail['deleted']!="Yes") {
?>

<tr>
<td>{parent_first_name}</td>
<td><?php echo $detail['parent_last_name']; ?></td>
<td><?php echo $detail['contact1_name']; ?></td>
<td><?php echo $detail['contact1_phone']; ?></td>
<td><?php echo $detail['contact2_name']; ?></td>
<td><?php echo $detail['contact2_phone']; ?></td>
<td><?php echo $detail['child1_first_name']; ?></td>
<td><?php echo $detail['child1_last_name']; ?></td>
<td><?php echo $detail['child1_dob']; ?></td>
<td><?php echo $detail['child1_medical']; ?></td>
<td><?php echo $detail['child1_notes']; ?></td>
</tr>
<?php if($detail['child2_first_name'] !=""): ?>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td><?php echo $detail['child2_first_name']; ?></td>
<td><?php echo $detail['child2_last_name']; ?></td>
<td><?php echo $detail['child2_dob']; ?></td>
<td><?php echo $detail['child2_medical']; ?></td>
<td><?php echo $detail['child2_notes']; ?></td>
</tr>
<?php endif; ?>
<?php if($detail['child3_first_name'] !=""): ?>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td><?php echo $detail['child3_first_name']; ?></td>
<td><?php echo $detail['child3_last_name']; ?></td>
<td><?php echo $detail['child3_dob']; ?></td>
<td><?php echo $detail['child3_medical']; ?></td>
<td><?php echo $detail['child3_notes']; ?></td>
</tr>
<?php endif; ?>
<?php if($detail['child4_first_name'] !=""): ?>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td><?php echo $detail['child4_first_name']; ?></td>
<td><?php echo $detail['child4_last_name']; ?></td>
<td><?php echo $detail['child4_dob']; ?></td>
<td><?php echo $detail['child4_medical']; ?></td>
<td><?php echo $detail['child4_notes']; ?></td>
</tr>
<?php endif; ?>
<?php if($detail['child5_first_name'] !=""): ?>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td><?php echo $detail['child5_first_name']; ?></td>
<td><?php echo $detail['child5_last_name']; ?></td>
<td><?php echo $detail['child5_dob']; ?></td>
<td><?php echo $detail['child5_medical']; ?></td>
<td><?php echo $detail['child5_notes']; ?></td>
</tr>
<?php endif; ?>
<?php if($detail['child6_first_name'] !=""): ?>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td><?php echo $detail['child6_first_name']; ?></td>
<td><?php echo $detail['child6_last_name']; ?></td>
<td><?php echo $detail['child6_dob']; ?></td>
<td><?php echo $detail['child6_medical']; ?></td>
<td><?php echo $detail['child6_notes']; ?></td>
</tr>
<?php endif; ?>
<?php
}
endforeach;

?>
</table>
Gr GreyHead 26 Jan, 2017
Answer
Hi stikki,

This line should have [] and not ()
$date=$form->data('camp_date');
- that may be the problem.

If you are also using this in an email then it might be simpler to remove all of the 'table' section from here into a Custom Code action where you build $form->data['table'] that can then be included in both places.

Bob
Max_admin Max_admin 26 Jan, 2017
Hi,

Try with the table html content and some static data (no PHP) into the pdf action, does it work ?

Try this code in the pdf content:

<?php pr($form->data['day']); ?>


Best regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
This topic is locked and no more replies can be posted.