Use PHP to replace fields in word template with form data

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ldupreez
Forum Newbie
Posts: 4
Joined: Wed May 09, 2012 8:32 am

Use PHP to replace fields in word template with form data

Post 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.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Use PHP to replace fields in word template with form dat

Post 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.
ldupreez
Forum Newbie
Posts: 4
Joined: Wed May 09, 2012 8:32 am

Re: Use PHP to replace fields in word template with form dat

Post 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?
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Use PHP to replace fields in word template with form dat

Post 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.
x_mutatis_mutandis_x
Forum Contributor
Posts: 160
Joined: Tue Apr 17, 2012 12:57 pm

Re: Use PHP to replace fields in word template with form dat

Post 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.
ldupreez
Forum Newbie
Posts: 4
Joined: Wed May 09, 2012 8:32 am

Re: Use PHP to replace fields in word template with form dat

Post 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?
x_mutatis_mutandis_x
Forum Contributor
Posts: 160
Joined: Tue Apr 17, 2012 12:57 pm

Re: Use PHP to replace fields in word template with form dat

Post 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.
ldupreez
Forum Newbie
Posts: 4
Joined: Wed May 09, 2012 8:32 am

Re: Use PHP to replace fields in word template with form dat

Post 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?
x_mutatis_mutandis_x
Forum Contributor
Posts: 160
Joined: Tue Apr 17, 2012 12:57 pm

Re: Use PHP to replace fields in word template with form dat

Post 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.
Post Reply