Using Variables to PHP

So, as you already know Wappler doesn’t have a pdf export function or plugin.

So I’m using fpdf to create pdf files from forms. I have the following php code that should run when the form is submitted.

<?php
require('js/fpdf/fpdf.php');

$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'¡Hola, Mundo!');
$filename= //GET FORM WAPPLER FORM//;
//Output the document
$dir = "documents/ArchivosGeneradosUF/"; // full path like C:/xampp/htdocs/file/file/
$pdf->Output($dir.$filename.'.pdf','F');
?>

First question: how do I send the variables from wappler to the php file? (in the code the $filename value should be retreived from the form)

Second question: how do I run that php code (of course sending the data that should be used)

I think you could use a session variable to do this. You could send the filename to a server action which would store the value in a session. On server action success, you could go to your PHP page which would read the session value and then do whatever else it needs to do.

It’s prefectly explained, but I really don’t know how to get it done.

In fact, I added the pdf script to the server connection action but it didn’t work. If I use it in a file separately it works fine.

Use a hidden field in the form, the field will have the value of the filename. Then use $_POST value in your PHP script.

@ben’s solution is probably a better and simpler solution.

I was thinking of a case where I needed to pass variables to a PHP script and also needed to involve server connect to retrieve data, in which case using session variables is an option.

Ok. Thanks. But how do I get it done if the server connection file won’t even work with the included code of the fpdf

I would use the PHP file separately - incorporating into a server action file would probably make things complicated or just not work. You should be able to pass whatever you need to the PHP script - eg using POST variables as @ben suggested (or sessions, cookies etc.).

1 Like

Ok. And how do i “invoke” the php file when the form is submitted?

El El jue, 24 oct. 2019 a la(s) 06:54, TomD via Wappler Community noreply@community.wappler.io escribió:

I wouldn’t have thought you would need to do anything special - just enter the PHP filename as the form action attribute.

2 Likes

Carlos, although I used to use FPDF in a life previous to Wappler, I have listened to @patrick who said, why don’t you let the browser do the hard work?

I then went over to the DMXzone site and copied the code that they use, with great succes. An example can be found at https://pleysier.com.au/carlos/, where you can see that I have used App Connect variables (db not connected) to populate the page.

1 Like

Ok. I’ll take the tip. Using this method, how do I automatically save the pdf file generated to the server directory?

No need to save the PDF file. The template is the HTML document which is populated by App Connect variables which in turn receives the data from the database.

1 Like

As an example, these are the invoice for products that I have purchased

image

When I click on any one of the entries, I am taken to the Invoice page ready to be printed or converted to PDF for download.

4 Likes

Thanks Ben!! How do you get the data for the printable page? Which method is the best one?

Hi Carlos, you are ahead of me (or rather, I am lagging behind) This will all be part of my wCart Tutorial which I will hopefully finish off this weekend. Please bear with me.

wCart tutorial? I think that’s exactly what I need. Looking forward to it.

There is already I believe nine parts to the tutorial finished. Here is part one …

1 Like