Solved

Interactive HTML form with PDF output and database saving feature

Posted on 2009-05-11
2
539 Views
Last Modified: 2013-12-12
I am trying to streamline a process at my office that works as follows:

1.  Someone gathers all of the data from client, and fills out a certain form (really long form).
2.  Based on this form, the project managers fill out a second form - then they convert this form to PDF and send it over to our hosting company for setup.
3.  Then with the form that has been returned, they update a third spreadsheet which serves as a data repository.

As you can tell, this is a tedious process, and I want to revamp it.  I have a simple solution:

1. The client fills out Form A on a certain website (i can run it on a linux or a windows box).

2.  Based on the response from the client, generate a pdf that can be emailed directly to the hosting company.

3.  Once the hosting company is done setting up the connection, the project manager can go on the website and complete the form that was started in step 1.

4.  Once done, it will update either the excel sheet directly, or store everything in a database (either one is fine).

In other words, need a form that saves data to a database and generates a PDF.  And then has the ability to update the form and the backend with new information.

I can really do this myself and spend 10 hours developing an app.  That would be terrific, but is there any tool that I can use? If so, that would greatly reduce the time needed for me to develop this procedure...  
0
Comment
Question by:shahyan
2 Comments
 
LVL 8

Accepted Solution

by:
Bobaran98 earned 500 total points
ID: 24361423
Great question!  I think what you're looking for can be done with PHP, MySQL, and Adobe Acrobat Professional (not sure what version minimum, but I think 8 is fine).

Okay, so your process:
  1. You use Adobe Acrobat to design the PDF template(s) for the forms to be filled out (I'm sure you're familiar with the PDFs that have editable fields, right?).
  2. You make an HTML form version of that PDF template.
  3. You create your MySQL table to store data from form submissions.
  4. You make a PHP file to accept form submissions, validate, and write data to the MySQL table.
  5. You make a PDF generator in PHP which grabs entries from the MySQL database and pushes the data into the PDF.
That's the simple version.  The step-by-step version is here:  http://koivi.com/fill-pdf-form-fields/tutorial.php

Note that this tutorial also explains how you can skip my step 2 (the HTML form) and have users provide data directly into the PDF template, then submit it to the database that way.  There are pros and cons to this, however.

The really cool part of the tutorial, of course, is where it shows you how to generate the PDF file from the MySQL data.  But you have to have that PDF template for it to work.  The way their code works, the file is saved to a directory on your website when all is done.  I would suggest instead that you change the code at the very end so that rather than saving the file on your site...

// write the file out
if($fp=fopen($fdf_dir.'/'.$fdf_file,'w')) {
fwrite($fp,$fdf_data,strlen($fdf_data));
echo $fdf_file,' written successfully.';
} else {
die('Unable to create file: '.$fdf_dir.'/'.$fdf_file);
}
fclose($fp);

... you instead echo the file data to the browser; because the data includes a mime type specifying the data as PDF, it will probably force the browser into an open-or-save-file dialog:

echo $fdf_data;
exit;

In fact, to build on step 5, I would call my PHP downloader script pdf_generator.php, and it would take one parameter on the querystring-- a unique form submission identifier so that you can pull all submission fields from the database.  That query would also give you the name of your PDF template file, which you could open, fill in, and echo directly to the browser to force download.  As a result, you could create links to pdf_generator.php?id=X the same as if you were creating links to JoeJohnsonsFormSubmissionOnMay252009.pdf.

Pretty cool, huh?  What do you think?  I'm not sure of the cost of Adobe Acrobat Professional, but this definitely isn't functionality that comes with the free one.  I can't imagine it's much though.

0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
This article discusses four methods for overlaying images in a container on a web page
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
The viewer will learn how to dynamically set the form action using jQuery.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now