Help with PDFtk function

Did this
$refcode = $_GET[“reference_code”];

and got this

QKEX49MKDE

tried this
$refcode = filter_input(INPUT_GET,$_GET[“reference_code”]);

and got this
" ****** "

The use of two pages was just how I figured it would work as I planned to put some other instructions about downloading or printing in the space under the form later if needed.

So if using one page allows the customer to see the form, view possible instructions and submit refcode then show the finished pdf, thats fine with me. That actually sounds like less work when I consider that I have other documents that I will have to do this with.

Okay, just use the $refcode = $_GET[“reference_code”]; and it should work.

But, yes, I usually put all code that has to do with a form in one page, it also gives you a nice way to throw out an error message. Like if the user gives you an invalid ref-code, you can return to the form with a fancy display of the error message. If you want to do it in one page, I will post a new version of it with all the parts in place and the error message area added in, too. Should not take long.

1 Like

that sounds good to me… I was gonna try and put it together myself and show you but my obvious first question was gonna be what to do with the form action =. So I’ll let you show me how the pro’s do it and ask questions if there is something I don’t understand.

Just used the

//query for reference_code from ‘forms’ table
$refcode = $_GET["reference_code"];

$mysqli = new mysqli($server, $username, $password, $dbase);

$query = "SELECT name,data FROM thetitl1_livesite754.form_data WHERE form_id IN(SELECT id FROM thetitl1_livesite754.forms WHERE reference_code = '".$refcode."')";

$results = $mysqli->query($query);

$new_form = file_get_contents("TX_Title_App.html");

//Replaces form_fields in html temp with "data"
if ($results) {
//below is the line referenced in error message above     
while ($row = mysqli_fetch_assoc($results)) {
        echo $row["name"] . ":" . $row["data"] . "<br>";
       $new_form = str_replace($row["name"], $row["data"], $new_form);
 }
}

and got this:
VehVin6:123456
VehVin:12345678901234567
VehPlt:xxx-xxxx
VehYr:xxxx
VehMk:DODGE
VehMod:DURANGO
VehBdy:LL
VehClr:RED
VehMil:100000
VehWght:4400
VehCry:1000
ID#:19097667
IDOrgn:TX
PassOrgn:
Own1st:MICHAEL
OwnMid:A
OwnLst:HERNANDEZ
OwnEnty:ABC TRUCKING
OwnCnty:HARRIS
OwnAdd:4606 BRADY
OwnCty:HOUSTON
OwnSt:TX
OwnZp:77011
PreOwn:MIKE REYES
PreCty:HOUSTON
PreSt:TX
Dealer#:P-123456
LienDt:12-23-18
LienHld:CHASE BANK
LienAdd:1001 PRESTON
LienCty:HOUSTON
LienSt:TX
LienZp:77011
Sales$:1000.00
Tax$:62.50

I’m doing flipps over here, at age 50 and 300 lbs, that’s saying something…LOL

Okay, try this:
(Note: Not really tested as I do not have your database. And, just off the top of my head…! Try it! )

<?php
//  Create a connection to MySQL
require 'dogs.php';

//  First clear the error message
$error_message = "";

//  Check if user posted the form, if posted process the PDF, if not skip and just display the form
if (isset($_POST["submit"])) {    
    //  Grab the reference_code that the user posted
    $refcode = filter_input(INPUT_POST, 'reference_code');

    //  We now have the ref-cde, now check if it is valid by getting the form's data
    $mysqli = new mysqli($server, $username, $password, $dbase);
    $query = "SELECT name,data FROM thetitl1_livesite754.form_data WHERE form_id IN(SELECT id FROM thetitl1_livesite754.forms WHERE reference_code = '".$refcode."')";
    $results = $mysqli->query($query);

    //  Replaces form_fields in html temp with "data" if found, if not show form
    if ($results) {
        //  Load base form template
        $new_form = file_get_contents("TX_Title_App.html");

        //  Replace all data into the form template
        while ($row = $results->fetch_array(MYSQLI_ASSOC)) {
            $new_form = str_replace($row["name"], $row["data"], $new_form);
        }

        //  Form is ready to convert into PDFnamespace
        require_once ("/home1/thetitl1/public_html/pdforms/dompdf/autoload.inc.php");   
        use "Dompdf\Dompdf";
        $dompdf = new Dompdf;
        use "Dompdf\Options";
        $options = new Options($options);
        $options->set('isPhpEnabled','true');
        $dompdf = new Dompdf($options); $dompdf->loadHtml($new_form);

        // (Optional) Setup the paper size and orientation
        $dompdf->setPaper(‘portrait’);

        // Render the HTML as PDF
        $dompdf->render();

        // Output the generated PDF to Browser 
        $dompdf->stream();

        // Save to file
        //   $output= $dompdf->output();
        //   file_put_contents('TXTitleApp.pdf', $output);
    }
} else {
    $error_message=" That Reference Code is NOT in our database!";
}
?>
<html>
<body>

<?PHP
    if ($error_message!="") {
        echo "<fieldset style='background-color: pink;'><legend>Error Found!</legend>" . $error_message . "</fieldset>";
    }
?>

<form action="#" method="post">
    <fieldset><legend>Final Details Reference Code</legend> <label for="reference_code">Enter Reference Code Here:</label> <input id="reference_code" name="reference_code" type="text" /></fieldset><br>
    <input name="submit" type="submit" value="Submit">
</form>

</body>
</html>

As soon as I click the link
https://pdforms.losttitleconnection.net/TX%20Title%20App%20Gate.php

it gives
Parse error : syntax error, unexpected ‘use’ (T_USE) in /home1/thetitl1/public_html/pdforms/TX Title App Gate.php on line 30

this is line 30
use “Dompdf\Dompdf”;

What link? I gave you the all-in-one page. Name it anything you want, like TEST.php and put it on your server and run it… No links.

Oh, wait, remove the double-quotes on both the USE lines. I needed them on my site, but not needed on yours!

SOrry!

yes it’s the link to the page I set this code on
https://pdforms.losttitleconnection.net/TX%20Title%20App%20Gate.php

still getting
Parse error : syntax error, unexpected ‘use’ (T_USE) in /home1/thetitl1/public_html/pdforms/TX Title App Gate.php on line 30

looking for missing {} () or ;

I also just read that these need to be up near the top before you do anything else.
require_once ("/home1/thetitl1/public_html/pdforms/dompdf/autoload.inc.php");
use Dompdf\Dompdf;
$dompdf = new Dompdf;
use Dompdf\Options;

It said to move these up just after your require-dogs line. Try that!

A fixed version:

<?php
//  Create a connection to MySQL
require 'dogs.php';

//  Set up the PDF library
require_once ("/home1/thetitl1/public_html/pdforms/dompdf/autoload.inc.php");   
use Dompdf\Dompdf;
$dompdf = new Dompdf;
use Dompdf\Options;

//  First clear the error message
$error_message = "";

//  Check if user posted the form, if posted process the PDF, if not skip and just display the form
if (isset($_POST["submit"])) {    
    //  Grab the reference_code that the user posted
    $refcode = filter_input(INPUT_POST, 'reference_code');

    //  We now have the ref-cde, now check if it is valid by getting the form's data
    $mysqli = new mysqli($server, $username, $password, $dbase);
    $query = "SELECT name,data FROM thetitl1_livesite754.form_data WHERE form_id IN(SELECT id FROM thetitl1_livesite754.forms WHERE reference_code = '".$refcode."')";
    $results = $mysqli->query($query);

    //  Replaces form_fields in html temp with "data" if found, if not show form
    if ($results) {
        //  Load base form template
        $new_form = file_get_contents("TX_Title_App.html");

        //  Replace all data into the form template
        while ($row = $results->fetch_array(MYSQLI_ASSOC)) {
            $new_form = str_replace($row["name"], $row["data"], $new_form);
        }

        //  Form is ready to convert into PDFnamespace
        $options = new Options($options);
        $options->set('isPhpEnabled','true');
        $dompdf = new Dompdf($options); $dompdf->loadHtml($new_form);

        // (Optional) Setup the paper size and orientation
        $dompdf->setPaper(‘portrait’);

        // Render the HTML as PDF
        $dompdf->render();

        // Output the generated PDF to Browser 
        $dompdf->stream();

        // Save to file
        //   $output= $dompdf->output();
        //   file_put_contents('TXTitleApp.pdf', $output);
    }
} else {
    $error_message=" That Reference Code is NOT in our database!";
}
?>
<html>
<body>

<?PHP
    if ($error_message!="") {
        echo "<fieldset style='background-color: pink;'><legend>Error Found!</legend>" . $error_message . "</fieldset>";
    }
?>

<form action="#" method="post">
    <fieldset><legend>Final Details Reference Code</legend> <label for="reference_code">Enter Reference Code Here:</label> <input id="reference_code" name="reference_code" type="text" /></fieldset><br>
    <input name="submit" type="submit" value="Submit">
</form>

</body>
</html>
  1. does this need to be in the html code or should it be in the php part.
  2. How do we clear a form field if there is no data provided in the form_data table
  3. It came through with form field names replace, but the form it rendere is still smaller than the 8.5 x 11 paper size.
  4. other than that, looks like I owe you a bottle of Henesey…

Just entered a ramdom non existant ref code and it simply rendered the form with form fields

Well, first, if you try to load the data, you need to check if you got data back for the code they entered.
Then, if the form data was found, process it and if not display an error.

BUT, that part is done before the form gets displayed. Therefore, you need to display an error message if
the form data is not found so the user knows to retype it. The mistake is that the IF($results) should not be.
It should be a check if the number of rows is >0. if (mysqli_num_rows($results)>0) instead. So, change that
and it will work better.

It should not process the form if you use a fake ref-code after that. Me-Bad!

LOL, I like Gentleman-Jack… LOL

One more thing…

I entered your test ref-code and it showed the data in the form. But, the form is still messed up. The data is too small and not aligned as it should. Awhile ago I sent you the template with those fixed. It was also full page not shrunk like it is now. Do you still have that version?

May have missed that template you sent somewhere… I’ll check back through the thread and see if I have it either here or on a private message.

As to the error message part, the page loads with the error message displaying, when I enter a non existent ref code the error message just goes away… it seems to be working backwards for some reason…

https://pdforms.losttitleconnection.net/TX%20Title%20App%20Gate.php

replace the if($results) with the check for mysqli_num_rows…instead…

shoud

else {
    $error_message=" That Reference Code is NOT in our database!";
}

Come after

if (mysqli_num_rows($results)>0) {
        //  Load base form template
        $new_form = file_get_contents("TX_Title_App.html");

        //  Replace all data into the form template
        while ($row = $results->fetch_array(MYSQLI_ASSOC)) {
            $new_form = str_replace($row["name"], $row["data"], $new_form);
        }

And would it work if it looked like this instead…

else ($error_message!="That Reference Code is NOT in our database!") {
        echo "<fieldset style='background-color: pink;'><legend>Error Found!</legend>" . $error_message . "</fieldset>";
    }

Just trying to get the page to load without the pink area and only show it if a ref code come back with rows=0

No! The else set-error-message is above in the first part.
It is set to “” meaning nothing but still a string and then if there is no data found it is set to not-in-DB.

Then, later in the form display section, it shows the error if there was one. Two different parts!

Sponsor our Newsletter | Privacy Policy | Terms of Service