Saving PDF Link to Database

tim92109 20 Oct, 2015
I'm trying to save a record in the database, which is working fine... but I want to save the link (or at least the file name) of the PDF created via TCPDF.

The file name in data/files array is 'cf_pdf_file', which I thought I could just add when using the 'create database table' functionality in CF. I tried using that and it didn't work...

So I added the following PHP code between the TCPDF action and the Database Save action:
<?php
$form->data['pdf_link'] = "{$form->files['cf_pdf_file']['link']}";
?>

And created a new table, but this time I used the field 'pdf_link'. Still no luck (empty field in the database).

I had no issue, by the way, sending an email with the name of the PDF file using the directions found in CF documentation.

See anything I'm missing?
tim92109 20 Oct, 2015
UPDATE: It is now working. I think it was the cache (deleted cache from forms manager page). Few hours wasted for nothing, but at least it's working!!!

By the way, my original setup is what worked (using cf_pdf_file for the database column).
GreyHead 21 Oct, 2015
Hi Tim,

This should work - with fewer quotes and brackets
<?php
$form->data['pdf_link'] = $form->files['cf_pdf_file']['link'];
?>

Bob
tim92109 21 Oct, 2015
I actually got it working by deleting the cache, but that still helps. I had tested removing the quotes & brackets, but wasn't 100% sure if that was the correct syntax - but now I do. Thanks again, Bob!
HerKle 15 Nov, 2015
Hi,
I don't understand, how all this can work, when it's said elsewhere that TCPDF action has to be the last of all actions? So DB save has already happenend, e-mails are sent: what use can be made of $form->data['link']?

I dragged the TCPDF to second-last position and immediately everything was empty on the pdf. So I can neither attach it to an e-mail, which has been sent earlier, nor can I show the link on the confirmation page, because this is the second-last action before TCPDF produces all those information which is needed earlier?

What am I missing?

Thanks for enlightenment!
Regards,
Herbert
GreyHead 16 Nov, 2015
1 Likes
Hi HerKle,

It only has to be the last item if you are using the immediate display/download option. If you save the TCPDF to the server then it can occur anywhere appropriate in the action. The file details are added to the $form->files array like an uploaded file and the file name is added to the $form->data[''] array.

While developing, adding a Debugger action after the TCPDF action should show you these values so that you can use them in Email or DB Save actions - or in a Custom Code action if you want to rename or relocate the file.

Please see this FAQ and the CFv4 FAQ it links to.

Bob
HerKle 16 Nov, 2015
Thanks again, Bob!

Your answers are always helpful. Maybe this one should be added to the FAQ you mentioned, since the latter is quite brief (in comparison to the CFv4 faq).

I meanwhile read the tons of forum posts I found for "tcpdf" and I tried myself that beloved action. I agree to most of what you wrote with the exception that, even when set to "save to server" a tcpdf action may not be followed by a custom code action. It accepts only being followed by e-mail actions.

I wanted to unset the form->data var in the very last custom code action, to avoid messing with the form input by using back buttons etc.
Alas, this resulted in a blank pdf showing only the header. So I had to remove the custom code action and leave the var set. Too bad.

I presume the bug fix of CFv4 won't work in CFv5, because I couldn't find the mentioned text string "$mainframe" in any of the files in the administrator/components/com_chronoforms5/chronoforms/actions/tcpdf folder?

Have a nice monday!
Regards,
Herbert
GreyHead 16 Nov, 2015
Hi Herbert,

PHP in a Custom Code action should work OK. Do you remember what code you used? It's possible that unsetting $form->data might cause some side-effects.

Bob
This topic is locked and no more replies can be posted.