Jump to content

Simple html form to Word document


lhodgett

Recommended Posts

Hey All,

 

Firstly i'd like to say i'm no web developer .... :tease-01:

 

I've been asked to see if i can get a small site setup where we can track equipment, all i'm trying to do is have a html form with a few fields and pass the text into a word document.

 

All i have so far is something very simple (form)

<html>
<body>
<form class="firstresume.php" method="post">
Name: <input type="text" name="name">
Email: <input type="text" name="email">
<input type="submit">
</form>

<a href="firstresume.php">LINK</a href>

</body>
</html>

Second page:

<?php
        header("Content-type: application/vnd.ms-word");
        header("Content-Disposition: attachment; Filename=SaveAsWordDoc.doc");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=Windows-1252\">
<title>Saves as a Word Doc</title>
</head>
<body>
<h1>Header</h1>
  This text can be seen in word
<ul>
<li>List 1</li>
<li>List 2</li>
</ul>
</body>
</htm>
<html>
 <body>

 Hello <?php echo $_POST["name"]; ?>!<br>
 Your mail is <?php echo $_POST["mail"]; ?>.

 </body>
 </html>

I've done a lot of research but nothing has really helped, so i thought i'd give this forum a try.

 

I can pass the variables from one page to another with no issues, but including a word document i cant get it to work.

 

Any help would be appreciated.

 

Thanks,

Link to comment
Share on other sites

Why would you want to save the text into a word document? Or, here's another way to put it: why a word document? (the solution is just going to confuse you if you're not a developer). if the purpose is just getting the text from the form into a file, for heaven's sake just use a .txt file (word will open it up nicely too)...

 

All you would need would be something like: 

 

$var = "Hello " . $_POST['name'] . "!\nYour mail is: " . $_POST['mail'] . "\n";

file_put_contents('filename.txt'.$var);

 

you can even name your text file something.doc instead of .txt... 

Edited by WebStyles
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.