sending form data into word document

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
londoneagle
Forum Newbie
Posts: 4
Joined: Fri Dec 04, 2009 4:41 am

sending form data into word document

Post by londoneagle »

Hi all,

I have online application form where students fill all the details and the data is delivered into an email address. All this is working just fine. Now what I wants is, the data to appear in the Application form (word document). So lets say when the student fills the online form via website, the details appears on the Application form so that when we print from the college it gets printed as if the student filled in the application form.

I tried using the word document to have a send button on the word document itself but it had security issues + complication for the user(to enable macro stuff) so that option is not practical...

Any suggestion please...


While surfing around, I found a quality web hosting provider you might like. You can get to it using the link below. http://www.arvixe.com/586.html
Marinusjvv
Forum Commoner
Posts: 29
Joined: Wed Dec 02, 2009 5:59 am

Re: sending form data into word document

Post by Marinusjvv »

Do you wish to take the details from your database and fill it in a Word doc? I have a method, but it's rather long..
Marinusjvv
Forum Commoner
Posts: 29
Joined: Wed Dec 02, 2009 5:59 am

Re: sending form data into word document

Post by Marinusjvv »

Well the method i use can take info from either your form or your database. Not from email. Let me know?
londoneagle
Forum Newbie
Posts: 4
Joined: Fri Dec 04, 2009 4:41 am

Re: sending form data into word document

Post by londoneagle »

thx for the quick response... I have access to only mssql database as my hosting is on .net
Marinusjvv
Forum Commoner
Posts: 29
Joined: Wed Dec 02, 2009 5:59 am

Re: sending form data into word document

Post by Marinusjvv »

Ok well let me explain this.. It's going to take a while.
londoneagle
Forum Newbie
Posts: 4
Joined: Fri Dec 04, 2009 4:41 am

Re: sending form data into word document

Post by londoneagle »

is that good ?
Marinusjvv
Forum Commoner
Posts: 29
Joined: Wed Dec 02, 2009 5:59 am

Re: sending form data into word document

Post by Marinusjvv »

Basically, you create a template in Microsoft word, with all the headings, etc, And use keywords in the document where you need to replace the words with user's info, for example- User name : User_Name.

When saving the document, select Web page (*.htm) from the Save as Type drop down. Then save it, obviously.

In your php file you do the following:

Code: Select all

// opens the file you created
$hlines = file("filename.htm");
// creates a new word document
$handle = fopen("C://Newdoc.doc","w+");
// here you replace all the keywords with user's information
foreach($hlines as $hline_num => $hline)
{
    $hline = str_replace("User_name",$_REQUEST["User_name"],$hline);
        $hline = str_replace("User_tel",$_REQUEST["User_tel"],$hline);
        // etc
        fwrite($handle,$hline."\n");
}
It then creates the file at the destination you chose earlier (C://Newdoc.doc)
Marinusjvv
Forum Commoner
Posts: 29
Joined: Wed Dec 02, 2009 5:59 am

Re: sending form data into word document

Post by Marinusjvv »

Well the example i gave uses info from a form. You'll have to adapt it if your using a database, obviously.
londoneagle
Forum Newbie
Posts: 4
Joined: Fri Dec 04, 2009 4:41 am

Re: sending form data into word document

Post by londoneagle »

Hi,
Thanks for your tip but I cant seem to figure out the solution.

What I have now is an Application form (word 2007) and "apply online form" (html for form and php to send to an email)... these two are seperate.... students can either apply online (which comes via email) or download the word form fill up and send it to us.

.... the applyonline comes in an email format... and when we print, it does not look very credible.. so what we want is, the student details sent via online to be printed on the word document ... or a page similar to the word document rather than just the email format...

Available technologies I have is asp.net, php, word 2007 mssql 2008 and html obviously ...

many thanks...
Post Reply