Avatar of F Grace
F Grace
 asked on

TCPDF - Create PDF from Form Values and Link to PDF Download

Hi

I am working on a payment module and I wish to create an option to allow the user download a PDF version of their Receipt.

At the moment, I am capturing the form values and displaying a receipt of their payment on the page in HTML, like:
<p>Receipt for Purchase:</p>
    <ul>
    <li>First Name: $pfirstname </li>
    <li>Last Name: $plastname</li>
    <li>Address 1: $paddress1</li>
    <li>Address 2: $paddress2</li>
    <li>Town/Village: $ptownvillage</li>
    <li>Postcode: $peircodepostcode</li>
   <li>Mobile: $mobile</li>
    <li>Email: $email</li>
    </ul>

How do I create a link at the bottom of this to allow them download or open a PDF version of this with the form values?

Attached is the PHP file which uses TCPDF to create a blank PDF document on the server, but without the form values.

Greatful for any help :)
PDFPHP

Avatar of undefined
Last Comment
F Grace

8/22/2022 - Mon
Ray Paseur

Attached is the PHP file ...

?

F Grace

ASKER
Sorry, it's attached now :)
pdftest.php
ASKER CERTIFIED SOLUTION
Ray Paseur

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
F Grace

ASKER
Hi Ray

Thanks for your excellent response and clarity. I have followed all the steps and its all working up to the point of trying to create the temporary JSON file.

I get the following message:
Warning: file_put_contents(2017-03-09MyName.json): failed to open stream: Permission denied

The suggested solutions elsewhere are to set the folder permissions to 777 but surely this is a huge security risk?
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Ray Paseur

No, it's not really a huge security risk, and the permissions do not need to be 777.  On my server, I write things all the time.  The directories have perms set to rwxr-xr-x (0755) and the files seem to get rw-r--r-- (I think that's 0644) more or less automatically.
F Grace

ASKER
Excellent..got it working now, many thanks
F Grace

ASKER
Excellent answer, very detailed and easy to follow. Thanks for your help :)
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.