HMTL help: how do I output form data to a text file?

Ok, I am helping someone with test web pages designed to train students. One of the sample pages is a form that asks for various information (name, address, etc), and a submit button. What we’d like to do is set the page up so that it saves the form data to a text file, which can be reviewed by the instructor to verify the student has filled out the form correctly. Would be nice if I also had a way to create unique text files too (appending file name with the date or random number, for example).

I got a page with the form on it, the fields, submit button, etc, is all laid out. How do I get the page to save the form data to a plain text file when I push the submit button?

You’ll need something that runs on the server beyond just HTML to do this I think - CGI, ASP, PHP or some such. A basic HTML guestbook CGI might even work if you stripped all the HTML markup out of it.

Where is the HTML form posted, and do you know if any of the above are already installed on that server?

You need a form processing script of some kind. I’m most familiar with PHP. So what I would do is have the form send the data to my php script, using PHP I would get the ‘post’ data, process the data and then write them to a new text file (using a field from the form as the text file name). See http://www.tizag.com/phpT/forms.php and http://us.php.net/manual/en/function.fwrite.php

I don’t believe the web site is on the internet, I think they just have it on a file server. It’s a very simple page set up for the purpose of demonstrating to students what the different components of a web page are.

I do know some basic html, but I don’t really know anything about scripting. I did try putting a “mailto:” in the form action, and it sorta works but in the email attachment the file comes out like “&name=John+Smith&address=Main+Street&city=…”. I would rather see something like this:
name: John Smith
address: Main Street
city: Anytown

Like the others have said, you’ll need some sort of server-side language to do what you’re asking. Basic HTML won’t do it, although like you mentioned you can get a long URL encoded string and parse it out on your own with various find/replace macros. Basic HTML just isn’t set up to handle what you’re trying to do.

I should also note that using “mailto:” in the form action is not fool-proof. If the person using the form has not set up their email client, or doesn’t send the email, it doesn’t work.

There are 3rd party form processors out there that will do what you’re requesting as well, but basic HTML ain’t gonna cut it.

I have this exact problem! I teach classes in a prison environment, and we are not allowed access to the internet. This is problematic when attempting to teach students who have been incarcerated for extended periods of time, that need to develop skills at navigating web sites and completing applications. The print function is an important piece since it would allow students to visualize what an employer is going to see once the form data is extracted. Filling out the application these days is the first test in any job search and employers definitely eliminate candidates based on formatting and similar issues that have nothing to do with work ethic and job-related skill sets. Were you ever able to find a workable solution that would allow the data that was entered to be printed?

Thank you for your help! :smiley:

Are you trying to teach them web programming skills or just how to fill out a form? What kind of computers and software DO they have access to? I assume they have access to a web browser, even if they can’t actually get on the Internet? Where are the webpages they are allowed to access, then?

If you can install software on their computers, you can easily set up a server (like XAMPP) and use PHP to do this all locally. XAMPP is a web server package that lets anyone on the local network access your webpages and scripts, even without internet access.

Otherwise, a really hack-y way to do it without installing anything is to code a HTML page with JavaScript/jQuery and CSS. After they fill out the form, the JavaScript pretends to submit it but actually just hides the form and pops up a hidden div that’s been CSS-formatted to look like a printed document.

Here is a HTML5 example, and here is an IE/activeX example

Your mailto attachment is coming out funny because you are posting multiple fields: you need to take the values of the fields and concatinate the the text into one field before you post or save the data. This is what the web server would do if you posted the fields back to a web server.

If you need to, you can use a Word or Excel (or vbscript or shell script) macro to convert that posting-format data string into a document.

I wanted to tell you both thank you - we have the “website” up and running now, and it will be a great tool for my classroom! I really appreciate you taking the time to answer my question and come up with a fix :smiley: