How to insert data from database into TCPDF action

goliath 01 Apr, 2015
I managed to create a simple form in CF 5 (which connects to CC 5) that shows the correct data of a record.
But when I try to save this data into a TCPDF action is seems to go wrong. The PDF file is created but I can only see {field_name} and not the data itself.

So in the form itself the data is displayed correctly but in the TCPDF action the data isn't stored. Maybe I'm forgetting something but what?
GreyHead 01 Apr, 2015
HI geertmartens,

Impossible to say from the information here.

Please add a Debugger to your form and post the output here and also at least a part of the PDF template you are using.

Bob
goliath 02 Apr, 2015
The TCPDF template is very easy: in the 'Contents' field I just put:

{email}
{voornaam}
{achternaam}
{adres}
...


This is the result:

----------
Data Array

Array
(
    [cont] => lists
    [ccname] => Mandatenverzending
    [act] => edit
    [gcb] => 10
    [chronoform] => mandaten-verzending
    [event] => submit
    [button24] => E-mail
    [voornaam] => 
    [Mandatenverzending] => Array
        (
            [achternaam] => Smith
            [email] => john.smith@email.com
            [telefoon] => 01234567
            [adres] => Adreslijn
            [postcode] => 1234
            [plaats] => City
            [gebplaats] => Capital City            
        )

    [pdf_file_name] => toekenning_mandaat___20150401154933
    [toekenning_mandaat] => toekenning_mandaat___20150401154933.pdf
    [naam] =>  
)

----------
Debug info

Array
(
    [4] => Array
        (
            [TCPDF] => Array
                (
                    [0] => /path-to-server/toekenning_mandaat___20150401154933.pdf has been saved correctly.
                )

        )

    [5] => Array
        (
            [Email] => Array
                (
                    [0] => An email with the details below was sent successfully:
                    [1] => To:
                    [2] => Subject:The subject title
                    [3] => From name:Sender's name
                    [4] => From email:sender@email.com
                    [5] => CC:
                    [6] => BCC:
                    [7] => Reply name:
                    [8] => Reply email:
                    [9] => Attachments:
                    [10] => Array
                        (
                            [0] => /path-to-server/toekenning_mandaat___20150401154933.pdf


It seems that the system doesn't recognise the {fields}. Is there any code I have to insert anywhere?

In CF 4 there wasn't any problem (the only thing different there is that I used the 'HTML to PDF' action).
GreyHead 04 Apr, 2015
Hi geertmartens.

Looking at the Debugger output some of the data is in a sub-array
 [Mandatenverzending] => Array
        (
            [achternaam] => Smith
            [email] => john.smith @[at] email [dot] com
            [telefoon] => 01234567
. . .
So, in the template I think you would need to have something like this:
{Mandatenverzending.email}
{voornaam}
{Mandatenverzending.achternaam}
{Mandatenverzending.adres}
...

Bob
goliath 07 Apr, 2015
Indeed Bob. When I change this it's OK again!
Thanks!

The PDF file name is a combination of the flelds 'voornaam', 'achternaam' and the date.
I use the following PHP code to generate this:

<?php
$datum = date('YmdHis');
?>

<?php
$form->data['toekenning_mandaat'] 
= $form->data['pdf_file_name']
= "toekenning_mandaat_"
.$form->data['achternaam'].
"_"
.$form->data['voornaam'].
"_"
.$datum;
?>


This doesn't work because the fields 'achternaam' and (now also) 'voornaam' are in a sub array. So, how do I do so now?
GreyHead 07 Apr, 2015
Hi geertmartens,

You have to use the PHP sub-array syntax here
<?php
$datum = date('YmdHis');
$form->data['toekenning_mandaat'] 
  = $form->data['pdf_file_name']
  = "toekenning_mandaat_{$form->data['Mandatenverzending']['achternaam']}_{$form->data['Mandatenverzending']['voornaam']}_{$datum}";
?>
or, a bit shorter:
<?php
$m = $form->data['Mandatenverzending']
$form->data['toekenning_mandaat'] 
  = $form->data['pdf_file_name']
  = "toekenning_mandaat_{$m['achternaam']}_{$m['voornaam']}_".date('YmdHis');
?>

Bob
goliath 07 Apr, 2015
Thanks Bob! It works fine now!
This topic is locked and no more replies can be posted.