lhodgett Posted February 19, 2014 Share Posted February 19, 2014 Hey All, Firstly i'd like to say i'm no web developer .... 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 More sharing options...
WebStyles Posted February 19, 2014 Share Posted February 19, 2014 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... Link to comment https://forums.phpfreaks.com/topic/286308-simple-html-form-to-word-document/#findComment-1469566 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.