Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Curtis Watson](https://secure.gravatar.com/avatar/83ca27865aadae353f1738ffae2d843b?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Curtis Watson
Courses Plus Student 356 PointsHTML Forms to print to text file
Okay, so I've made my form using the tutorials posted here. I would like the data inside the form to be saved to a text file on my server computer.
I had considered using PHP to e-mail it, however I can't quite get it to work, and I'd rather it just save a new text file. Same thing for using
<form action="MAILTO:xxx@xxx.com">
If you know the video I should watch, or have a solution I would be very grateful.
I'm guessing it's something to do with JScript, but I'm unsure
2 Answers
![Dustin Matlock](https://secure.gravatar.com/avatar/3dff96545659ddf9d1706ee4b628d6eb?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Dustin Matlock
33,856 PointsHi Curtis, I don't think Treehouse has a video specifically in regards to HTML form to a text file. However, below I have included a script from Stack Overflow.
<form id="some" name="someName" method="post" action="/ur/url/to/post">
<input type="text" id="some1" class="someClass" value="" name="fileWrite"/>
<iput type="submit" value="submit" class="submitClass"/>
</form>
$myFile = "testFile.txt";
if(isset($_POST['fileWrite']) && !empty($_POST['fileWrite'])) {
$fileWrite = $_POST['fileWrite'];
}
if($fileWrite) {
$fh = fopen($myFile, 'a') or die("can't open file"); //Make sure you have permission
fwrite($fh, $fileWrite);
fclose($fh);
exec('/your/command /dev/null 2>/dev/null &');
}
![Dustin Matlock](https://secure.gravatar.com/avatar/3dff96545659ddf9d1706ee4b628d6eb?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Dustin Matlock
33,856 PointsIt's PHP and most likely the best solution. However, below are a few other ways using JavaScript. The last one uses Node.js, although, I'm not sure exactly how to implement that.
Curtis Watson
Courses Plus Student 356 PointsCurtis Watson
Courses Plus Student 356 PointsI'm assuming this is JavaScript yes?