Thanks for the response Ernie,
I’m leaning toward your option, as you are the one providing guidance on a manner you are familiar with. That would seem to be the better way. I can provide my email via pm, if that makes sending files easier. This may be asking much, but I’d also like to see if we could possilbly have a phone conversation as well, to better understand what needs to be done as I assume there is much that needs to be understood and communicated on both our sides. I think doing it that way would be better done as opposed to typing out a small paper back journel here and wasting time by being lost in translation to some degree. If that is possible, I’d appreciate it and will send my number via private message, if that is okay with you. Though, I’ll wait for permission to do so
Very interesting on how converters work. I experimented all morning to help you with various converters. Ran thru tons of online ones. I found a really good one, but, it is expensive. ($149.00) How many forms do you need to have in your system? If you have only a few, you can convert them for free for seven days using this tool. After that you have to pay the $149 to purchase it. Just curious how many forms we are talking about. It is called Able2Extract and works great! (Review the copy I send in a private message… (Review the actual code it created. I did add one line of CSS for the live-data…)
This converter did a really great conversion. Almost 100% accurate. AND, the way they created the HTML file was extremely cool! It is so very easy to locate the area you need to alter. I actually got excited because this gave me a very good template to play with for your one form you mentioned. I had to just add the area where the text was going to be put into the form. I will send a copy in a private message.
Now, how this would work is you edit the form and put in some fields for the data. Then, just use a few lines of code to pull all the live data out and then another short routine to replace the fields with your data. Not complicated at all. Here is one possible way to do it.
It the template (the PDF converted to HTML) you place codes with the actual live names of the fields in your database for the data that needs to be filled in. So, to put in a field name into your template, you will need something that is unique. In my code, I use something like ___first_name___
which is three underscores before and after the actual field name used in the database. So, in your examples above, you would use ___VehVin___
for the Vin#, ___VehYr___
, etc. This is only done once in the template. One time and it is done! It is tedious, but, is done one time and never again unless the form changes. A state form seldom changes, so not a big deal.
Next you would need code to get the live data. This would be a simple query. Like “SELECT * FROM owner_info WHERE ownerID=999” or something similar where you pull out the data you plan to place in the template.
To load the template, you simply load the entire HTML file into one variable. This would be your new version of the form. Just use this: $new_form = file_get_contents(“forms/form10U.html”);
Once you have those, you are all set to replace them in your new version of the PDF file. (We of course, are creating it in HTML format first and later will turn it back into a PDF file.) This is quite simple. You loop thru the row of live data and get the field name and data for each item. Then, you check if the field name exists in the template and if so, replace it with the live data. Loosely, something like this:
while ($row = mysql_fetch_assoc($query)) {
foreach($row as $key => $value) {
$new_form = str_replace("__" . $key . "__", $value, $new_form);
}
}
If a field exists inside the template, it is replaced with the live data. Simple. If it does not exist in the template, it is just skipped over. Handling of check boxes would require a different approach. You would need to replace the square for the checkbox with one that has an X in it. This would just be some similar code where the replace command checks for the boolean first. We can do that part another day.
Once this is done, just pass the one variable $new_form to the routine that would save it as a PDF file.
Easy to do with the library I mentioned… But for testing as a HTML file, you can just use this to save the variable: file_put_contents(“new_form130U.html”, $new_form); This writes the data out to a file so you can open it and see how the data fits in place.
To save as a PDF file instead of HTML, copy the DOMpdf library I mentioned above to your server and use the code I posted before to save it as a PDF or to display the PDF directly in the webpage. You load the HTML from the $new_form variable and then save it as a PDF file. Easy.
Well, it is my birthday today and I am leaving soon to go out to eat and to meet up with my friends. So, I might be quiet till tomorrow… But, you have something to start with…
Hope you had a great Birthday…
I wanna show you what I put together, I know it’s gonna need your touch but I think it atleast some framework to start with…
<?php
require 'connect.php';
//connection to the "reference" form on bondinsturct.html
var theForm = document.forms["reference"];
//gather reference_code from "reference" form on bondinstruct.html
var $refcode = "reference_code.innerHTML"
“SELECT * FROM finaldetails WHERE reference_code = "$ref-code";
$new_form = file_get_contents(“/130u.html”);
while ($row = mysql_fetch_assoc($query)) {
foreach($row as $key => $value) {
$new_form = str_replace("__" . $key . "__", $value, $new_form);
}
}
// reference the Dompdf namespace
use Dompdf\Dompdf;
use Dompdf\Options;
require_once ‘lib/dompdf/autoload.inc.php’;
// instantiate and use the dompdf class
$dompdf = new Dompdf();
$dompdf->loadHtml($new_form);
// (Optional) Setup the paper size and orientation
$dompdf->setPaper(‘A4’, ‘portrait’);
// Render the HTML as PDF
$dompdf->render();
// Output the generated PDF to Browser
$dompdf->stream();
// Save to file
$pdf_gen = $dompdf->output();
file_put_contents(“130uOutput.pdf”, $pdf_gen);
// Display PDF in browser
I’m still working on inputting column names on the HTML form, I need to create the connection.php file, and get some instructions on how to upload the dom lib to my root web folder. But I wanted to at least have this to show you. Like I said, my generation of code from scratch still needs a lot of work, so please bear with me.
Again, I hope you had a great time with friends and hope they let you win.
it didn’t paste the final lines of code correctly
// Display PDF in browser
echo $dompdf->output();
Well, the night was a bit , um, rough on me! I overindulged… LOL But, a fun time and I won $30 at cards. Got up very late today… Fun time!
So, the last line will for the browser to show the PDF file. Not needed if you are just saving the file to email to someone.
To copy the library, you just need the DOMPDF folder to be loaded on your server. In my server I placed it in a folder call “lib” for libraries as there were several in use on the site. Therefore the require_once ‘lib/dompdf/autoload.inc.php’; which points to the library folder and then the dompdf folder… That is all you need to do for that part. If that is the only library you are using, you can skip the lib folder and just use the dompdf folder. Make sense? Let me know how it works for you…
Good to hear you had a good time, overindulgence and make for great memories sometimes…If you can remember them, LOL
So I put together some php code, don’t know how functional it is or if it is even right…I’ll let you be the judge.
As for the DOMPDF file, I can work with what you just gave me to get that straight
I’m working on putting the field names in the html file, got it uploaded to my server and is showing the way it’s suppose to, my question is, do I need to put " " around each field like so “VehVin” , “Own1st” or will the code just recognize the uniqueness of each with out them and replace each with the data.
As for posting, when a customer click a button to generate the pdf, I like to show it in the browser and then give the save as, download or email option. Simply becuase, some people will do this on mobile device, some on desk top, and others may do it on a shared computer.
By the way, where are you located… I’m going to assume no where near the Florence storm region, but if you are or have family and friends who might, I hope they are all okay. I’m in Houston and we are suppose to be having a Trop Storm hit us this weekend too…prayers for the safety of you and yours.
PS…I your still feeling the effects of last night, have a cold beer…sounds crazy but it helps. Years of experience, let me tell ya, LOL
Just thought to ask this, but when the DOMPDF functions replaces the data, say for instance there is no lienholder info. I assume because there is no data there it would replace it with an empty space and not leave the field, correct?
another level of success just loaded all my html temps with their backgound files and they are presenting just fine… Now it’s just entering the fields on all of them. I’m going to leave that for later. Want to get this to work on just one form for now and then I’ll worry about extending out to those…
Fine today! Just lost yesterday due to not being able to concentrate…
Looks like you have been busy. If you use a template, you need to replace all fields. You can replace them with spaces or nothing. We can adjust the code to do that if there is no data in the field.
On the DOMpdf library. It is just a way to turn HTML into a PDF. So, the two options are to view it in a browser or save it as a file. I usually just put two buttons. One that says SAVE and one for VIEW. Then, the user can select which they prefer.
I noticed you did not include the CSS code I added to the template. You need that to make the lettering larger so it looks correct. But, you can fiddle with that later on.
.live-data{font-family:"Calibri Italic",serif;font-size:14.1px;color:rgb(0,0,0);font-weight:normal;text-decoration: none; margin-left: 5px;}
This is that CSS code you were speaking of, right?
Yes, it is just one I made up to make the text larger and put a small space at the beginning of each one.
Otherwise, it is too small and just does not fit correctly…
You can change the name to something that fits your own standards…
So here is where I’m so far… I also posted this a new topic in MySQL Beginners, in case you can’t help with the MySQL questions…and because I don’t want to be a burden on your time.
This is an image of data that I need to use to fill an HTML template that will then be used to create a pdf doc using the docpdf lib. I am querying this in MySQL using the following statement:
SELECT * FROM `thetitl1_livesite754`.`form_data` WHERE (CONVERT(`form_id` USING utf8) LIKE '29') ORDER BY `form_data`.`form_field_id` ASC
As you can see the ‘name’ column has values like VehVin6, VehVin etc.,… and the ‘data’ column has the actual info that I need to fill in the HTML template fields that correspond to the ‘name’ column data.
my question is…
Is it easier to make a php code that will make a MySQL connection and then fetch each ‘data’ value from this query using the 'form_field_id" and matching it for what the form field is in the HTML template that needs to be replaced?
Or is it better to create a table called finaldetails, create columns for each value in the ‘name’ column and then somehow assign the values in the ‘data’ column of this query to the associated column and then fetch that data?
Here is the project scenario, each customer is provided with a reference code when they submit a “finaldetails” form (http://losttitleconnection.net/finaldetails). After processing payment for their service the will see the “instruct” page (http://losttitleconnection.net/bondinstruct) where they will be asked to input that reference_code. If you move to the very bottom of this page there is a list of yellow buttons, one of which has the words “Application For Texas Title” at the very bottom. This is the HTML template (https://pdforms.losttitleconnection.net/TX_Title_App.html) that I am working with and I want to push the MySQL data to using php code. I have a php code file created, but as you can tell it is in need of proper coding to complete this process successfully. This is a copy of php code structure thus far that is connected to the link button. It is a work in progress of course
<?php
var theForm = document.forms["finaldetails"];
var $refcode = reference_code.innerHTML;
require 'dogs.php';
$sql = "SELECT * FROM `thetitl1_livesite754`.`forms`
WHERE (CONVERT(`reference_code` USING utf8) LIKE \'$refcode\')";
//I realize there are other lines of code that need to go here to complete the fetch
//of proper info to fill the html file below.
$new_form = file_get_contents(“/Tx Title App.html”);
while ($row = mysql_fetch_assoc($query)) {
foreach($row as $key => $value) {
$new_form = str_replace("__" . $key . "__", $value, $new_form);
}
}
// reference the Dompdf namespace
use Dompdf\Dompdf;
use Dompdf\Options;
require_once ‘lib/dompdf/autoload.inc.php’;
// instantiate and use the dompdf class
$dompdf = new Dompdf();
$dompdf->loadHtml($new_form);
// (Optional) Setup the paper size and orientation
$dompdf->setPaper(‘A4’, ‘portrait’);
// Render the HTML as PDF
$dompdf->render();
// Output the generated PDF to Browser
$dompdf->stream();
// Save to file
$pdf_gen = $dompdf->output();
file_put_contents(“Tx Title App.pdf”, $pdf_gen);
// Display PDF in browser
echo $dompdf->output();
?>
I’ve been working to understand how I can take information that the database can produce in a query and find the best way to structure my request in PHP so that it accomplishes my customers need for a preprepared pdf form that will be downloaded, printed or saved.
As I have said, a reference_code is issued per customer that has a ‘form_id’ associated with it in a ‘forms’ table. My overall thought was to perform a query using the ‘reference_code’ from "forms’ table like such:
$sql = "SELECT * FROM `thetitl1_livesite754`.`forms` WHERE (CONVERT(`reference_code` USING utf8) LIKE \'QKEX49MKDE\')";
Then create PHP code to gather the 'form_id" where the ‘reference_code’ matches.
Then the following statement to fetch the query for the image above:
$sql = "SELECT * FROM `thetitl1_livesite754`.`form_data` WHERE (CONVERT(`form_id` USING utf8) LIKE \'29\') ORDER BY `form_field_id` ASC";
And then just get some help with creating code that will take the info in the ‘data’ column that would associate each value with a field name in the template so that the field names are replaced with the data.
So then of course the question arose. Would it be easier to create a table with the info and use the existing php code to fill the html template as such
while ($row = mysql_fetch_assoc($query)) {
foreach($row as $key => $value) {
$new_form = str_replace("__" . $key . "__", $value, $new_form);
}
}
To me the latter would seem best, but as I’ve said, I don’t know who to go about it or if it is even possible.
Guidance on this would be of geat help. If you could please give me your perspective and an overview of what needs to be done. I can try to put it together and present it for further review
Honestly,
https://wkhtmltopdf.org/
I have used both. One is far easier than the other, which is why the company I was with at the time switched.
@astonecipher, thanks for the reference, but I’m just too far into doing this way to try and start all over with another process…
@ErnieAlex,
Hope you had a great weekend…
You’ve been of great help in the past, do you mind giving me your input on this. Your insight thus far has been lots of help in getting me this far.
Obi Wan Kenobi, your my only hope…LOL
The weekend was so busy and I had to work yesterday and today alot. Sorry I did not respond much…
Well, you already have the data in your table. Just read it using a normal SELECT * FROM… query. The question with this is which column identifies the data for this one form? It appears to be the form_id column. Therefore, you would use something like SELECT * FROM thetitl1_livesite754 WHERE form_id=29
Then, use the code I gave you, but, change it slightly to replace the template names with the data in your table.
Something like:
$new_form = file_get_contents(“/Tx Title App.html”);
while ($row = mysql_fetch_assoc($query)) {
$new_form = str_replace("__" . $row["name"] . "__", $row["data"], $new_form);
}
You can add in some checks for blank data. And, perhaps some formatting of various fields as needed.
Here is an example of how to check for blank data:
while($row = mysql_fetch_assoc($query)) {
if($row["data"]=="") {
$new_form = str_replace("__" . $row["name"] . "__", "", $new_form);
} else {
$new_form = str_replace("__" . $row["name"] . "__", $row["data"], $new_form);
}
}
To explain, the query selects all of the data for the one form. The fetch grabs one row of data at a time and replaces each into the template where needed. IF there is no data, it replaces the field text with a blank. (Therefore removing the text of the field name so it shows nothing.)
Hope that helps…
Afternoon @ErnieAlex
Hey, buddy…no need to explain. I fully understand that you have other things to do in life. I’m just glad you’re looking out for me when you can and I really appreciate that. There are plenty of other people on plenty of other forums. Some are straight haters, some are just nay-sayers, and some are heroes in disguise. You, my friend, are one of those heroes. To that, I say, I Thank God for putting you in my path.
As to the code, it helps very much so… clear and concise. Exactly what I was looking for, just couldn’t figure out the precise way to do it. Now that I see your explanation, I feel silly for not being more attentive to how the code was asking for it.
So, going forward…This is what I’ve come up with:
Which of these is the best way to connect to the "reference" form on the .html page
______________________________________________________________________________
1) //Get a connection to the HTML form where "id = reference"
var theForm = document.forms["reference"];
//Get a reference to the select id="reference"
var $refcode = theForm.elements["reference_code"];
___________________________________________
2) //connects to the finaldetails form on bondinstuct.html
var theForm = document.forms["reference"];
// creating a variable for the "reference_code" text box
var $refcode = reference_code.innerHTML;
_____________________________________________________________________________
//create connection to mysql
require 'dogs.php';
//submit mysql query for reference_code to get $formid
$sql = "SELECT * FROM `thetitl1_livesite754`.`forms` WHERE (CONVERT(`reference_code` USING utf8) LIKE \'$refcode\')";
//relate $formid with the formid number for the related $refcode
while ($row = mysql_fetch_assoc($query)) {
$formid = ("__" . $row["reference_code"] . "__", $row["id"], $formid);
}
//submit mysql query for $formid data from 'form_data' table
$sql = "SELECT * FROM `thetitl1_livesite754`.`form_data` WHERE (CONVERT(`form_id` USING utf8) LIKE \'$frmid\')";
//request for html template with form_fields
$new_form = file_get_contents(“/Tx Title App.html”);
//Replaces form_fields in html temp with "data"
while ($row = mysql_fetch_assoc($query)) {
$new_form = str_replace("__" . $row["name"] . "__", $row["data"], $new_form);
}
// reference the Dompdf namespace
use Dompdf\Dompdf;
use Dompdf\Options;
require_once ‘lib/dompdf/autoload.inc.php’;
// instantiate and use the dompdf class
$dompdf = new Dompdf();
$dompdf->loadHtml($new_form);
// (Optional) Setup the paper size and orientation
$dompdf->setPaper(‘A4’, ‘portrait’);
// Render the HTML as PDF
$dompdf->render();
// Output the generated PDF to Browser
$dompdf->stream();
// Save to file
$pdf_gen = $dompdf->output();
file_put_contents(“Tx Title App.pdf”, $pdf_gen);
// Display PDF in browser
echo $dompdf->output();
?>
Can you please look this over for me… I ran it through something called phpfiddle.org and try to run it and it gave me the following message:
You input disabled function(s) by PhpFiddle : file_put_contents(“Tx Title App.pdf”, $pdf_gen)
But I’m not knowledgeable enough to know what that means.
I feel like I’m on the cusp of getting this complete and it will all be because of your help.
It means the fiddler can’t create files. You can ignore it.
You are very welcome.
Now, since we do not know your set up 100%, it is very hard to guess what you need. But, some thoughts that might help you.
Quite often, you need to debug code by forcing it to halt at certain places and display the data up to that point. This helps by letting you know that your data is 100% correct up to that point. For instance, if your data from your query is inaccurate, then the rest of the code will not work correctly. A row of data is just a PHP array. Therefore you can print it by displaying it. For instance, you can use the following and it will show the data stored in one row of data:
while ($row = mysql_fetch_assoc($query)) {
$temp = print_r($row, 1);
die( "<pre>" . $temp . "</pre>");
$new_form = str_replace("__" . $row["name"] . "__", $row["data"], $new_form);
}
This code will force your script to stop executing and display the entire row of data. This will allow you to make sure you are getting the correct data from your query. (Step #1) I do not understand why you need to covert to uft8? Was your database set up using a different uft version? Also, you could combine the two queries into one using a “join” so you do not need to routines to replace the variables. Normally the LIKE function requires %'s around the data not quotes. Depends on a lot of issues. One thing is there is seldom a reason you would want to use LIKE in creating a form of this nature. You would always want to use very exact numbers, never randomly similar ones. If you have two reference_code’s that are similar you would not know which one you are pulling out for the form. I don’t think that is what you want to do.
The rest appears to be okay.
Now, other issues. Fiddle’s are great. Especially for quick tests. They are not really designed to simulate a server. If you require a testing platform for use of a full server, you might like to look at WAMP which I use or one of the other types of emulators. WAMP is easy to download and install. It gives you a working server on your desktop or laptop with Apache based server, PHP, MySQL and other systems you might need to use. Might be better than any of the Fiddles.
But, on the Fiddle, you can comment out the file_put_contents line and it should show the output instead. Just do not save the file as Astone mentioned…