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
https://forums.phpfreaks.com/topic/286308-simple-html-form-to-word-document/
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... 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.