Page 1 of 1
Use PHP to replace fields in word template with form data
Posted: Wed May 09, 2012 8:35 am
by ldupreez
Hi All
I would appreciate some advice on where to start with this daunting task i have. Please also bear with me as i am fairly new to PHP.
I’ve created an online form for my clients to complete in order to get a quote. The only thing I can get this form to do so far is to email the captured data to an email address.
What I would like to achieve is the following:
1: Save the data captured by the client onto my database
2: then get php to recall that data and replace it with fields in a word .docx template I’ve created
3: Finally php must convert the created docx into a PDF doc which the client immediately get once they’ve clicked on the form’s “Get quote” button.
Re: Use PHP to replace fields in word template with form dat
Posted: Wed May 09, 2012 8:46 am
by Celauran
In the scenario you've described, I don't see much point in using a .docx file over, say, a text file. You'll have to redo the formatting for your PDF anyhow. For database CRUD, take a look at
PDO. For PDF generation, check out
FPDF.
Re: Use PHP to replace fields in word template with form dat
Posted: Wed May 09, 2012 9:25 am
by ldupreez
Thank you so much for you quick reply.
Its just easier for me to create templates in word.
Is there any tutorials on the net that can help with this?
Re: Use PHP to replace fields in word template with form dat
Posted: Wed May 09, 2012 9:33 am
by Celauran
ldupreez wrote:Is there any tutorials on the net that can help with this?
Help with what, specifically? The PDO book on the PHP site is full of examples and the FPDF site has a tutorials section.
Re: Use PHP to replace fields in word template with form dat
Posted: Wed May 09, 2012 9:38 am
by x_mutatis_mutandis_x
You can convert HTML to PDF easily using
HTML2PDF. That would eliminate your need to maintain a Word doc. template as well.
Re: Use PHP to replace fields in word template with form dat
Posted: Wed May 09, 2012 3:53 pm
by ldupreez
The word doc template is a quotation which include terms and conditions the client has to sign for and also contain a list of information required from them. From the data they have entered the php must determine how much the quote will be and replace those fields in the template. will i be able to do this with a pdf file?
Re: Use PHP to replace fields in word template with form dat
Posted: Thu May 10, 2012 9:17 am
by x_mutatis_mutandis_x
ldupreez wrote:The word doc template is a quotation which include terms and conditions the client has to sign for and also contain a list of information required from them. From the data they have entered the php must determine how much the quote will be and replace those fields in the template. will i be able to do this with a pdf file?
Convert the word doc into a HTML form (using CSS where necessary) and show it to the user as a web page on a browser. When a user submits the form, you can then process and show them a HTML page (that contains fields replaced with the quotes that you determine), and give them an option to download it as PDF.
As far as a signature is concerned, you can have them type their full name authorizing the document. If their hand written signature is required, well then you are left with no choice but to use a word document. In-fact the user needs to scan the hard-copy he/she signed.
Re: Use PHP to replace fields in word template with form dat
Posted: Tue May 15, 2012 2:11 am
by ldupreez
x_mutatis_mutandis_x wrote:ldupreez wrote:The word doc template is a quotation which include terms and conditions the client has to sign for and also contain a list of information required from them. From the data they have entered the php must determine how much the quote will be and replace those fields in the template. will i be able to do this with a pdf file?
Convert the word doc into a HTML form (using CSS where necessary) and show it to the user as a web page on a browser. When a user submits the form, you can then process and show them a HTML page (that contains fields replaced with the quotes that you determine), and give them an option to download it as PDF.
As far as a signature is concerned, you can have them type their full name authorizing the document. If their hand written signature is required, well then you are left with no choice but to use a word document. In-fact the user needs to scan the hard-copy he/she signed.
Their hand written signature is required, so what do i do then?
Re: Use PHP to replace fields in word template with form dat
Posted: Thu May 17, 2012 11:15 am
by x_mutatis_mutandis_x
Provide an ablilty to download the form (in PDF/Word), after it's filled, and after you process it. Then give them an ability to upload the form. But you need to validate if they are uploading the right form, and if it's been signed (which is quite hard to achieve). The best solution is to have them type in their full name.