HTML Form processing script

John Reynolds

Ecce homo
Veteran
The new boss wants an anonymous feedback form and I'm looking for a script to to dump the fields of a very simple html form to a local network drive. The html code is going to be very simple, and this I can handle; unfortunately, I'm no programmer, so I'm lost as to how to dump the answers into a file that can be opened by a Windows user. I just want clean, easily read text. . .not sure if I want it to append to the same file or not.

I'm assuming a Perl CGI script is what's needed, but I've no idea how to write it or integrate with my form page. Any help/suggestions/schooling would be greatly appreciated.

TIA

Edit: The html files are simply accessed via a shared network drive. We're not running a web server.
 
Last edited by a moderator:
Doing it without running a webserver makes it very difficult! It would be trivial with a webserver running a scripting language like PHP or ASP. Without a webserver you can't really do CGI at all. The only way I can think is to use a client-side scripting language like VBScript which can write to files etc. (I'm presuming you are working on Windows platform). To that end I've written you a quick example form and VBScript function that will process the data and write it to a file (if the file doesn't exist it will create it).
Code:
<html>
	<head>
		<title>Test Form Submission</title>
	</head>
<body>

	<script language="VBScript">
	<!--
	Sub SubmitForm

		Dim item, strFilePath
		Dim objFSO, myFile
		Dim TheForm
		Const ForAppending = 8

		strFilePath = "C:\results.txt"
		Set objFSO = CreateObject("Scripting.FileSystemObject")

		If NOT objFSO.FileExists(strFilePath) Then
			objFSO.CreateTextFile(strFilePath)
		End If

		Set myFile = objFSO.OpenTextFile (strFilePath, ForAppending, True)

		myFile.WriteLine("Form submitted at " & now())

	  	Set TheForm = Document.forms("myform")

	  	For Each item In TheForm
	  		If item.name <> "submitter" Then
				myFile.WriteLine(item.name & " : " & item.value)
			End If
		Next

		myFile.WriteLine(vbNewLine)

		myFile.Close
		Set myFile = Nothing
		Set objFSO = Nothing

		MsgBox "Thank you for submitting the form."

	End Sub
	-->
</script>

	<form id="myform" method="post" onsubmit="SubmitForm()">
		Name:<input type="text" name="name"><br>
		Age:<input type="text" name="age"><br>
		Sex:<input type="text" name="sex"><br>
		Weight:<input type="text" name="weight"><br>
		<br>
		<input name="submitter" type="submit" value="submit">
	</form>

</body>
</html>

The disadvantage of using VBScript is that it will only work in IE and you will have to allow ActiveX components to run. However, without running any kind of webserver then I think it's your only option (personally I'd at running Apache or IIS and doing it properly!).

If you need any more help or anything explaining, just ask! Just remember to modify the variable strFilePath to point to the absolute place where you want it to write the file. Just add as many INPUT options to the form as you want, the script will loop through them all.
 
Don't use HTML, without a webserver, it's just a formatting language.

Would it be possible to have a word document (read only), just do some vb macros, have them fill it out, and once they hit some save/submit button (one that you plant within the document, I think you can do that), make a copy of that file and dump the results in there or you should even be able to make that a text file so that should handle that?
 
Diplo said:
Doing it without running a webserver makes it very difficult! It would be trivial with a webserver running a scripting language like PHP or ASP. Without a webserver you can't really do CGI at all. The only way I can think is to use a client-side scripting language like VBScript which can write to files etc. (I'm presuming you are working on Windows platform). To that end I've written you a quick example form and VBScript function that will process the data and write it to a file (if the file doesn't exist it will create it).

The disadvantage of using VBScript is that it will only work in IE and you will have to allow ActiveX components to run. However, without running any kind of webserver then I think it's your only option (personally I'd at running Apache or IIS and doing it properly!).

If you need any more help or anything explaining, just ask! Just remember to modify the variable strFilePath to point to the absolute place where you want it to write the file. Just add as many INPUT options to the form as you want, the script will loop through them all.

Thanks for this example. Unfortunately, ActiveX is completely disabled as mandated by from above (I work on a large U.S. Air Force base and have no control over such issues). IE is the only browser installed on all workstations, but no way I can touch ActiveX settings for this script.

As for Saem's Word suggestion, off the top of my head I think such a document would contain metadata that would defeat the required anonymity.
 
Dump it out to a text file, I think you should be able to append to it, so it shouldn't collect any worrisome metadata, it'll just be one huge text file.

Either that or open up visual studio and start going through a C# tutorial and hack together something or the other.
 
I could help you with a servlet but you would have to install tomcat and umm I guess that is out of question.
 
if its closed enviroment (local network) you could install Apache and run web server on single machine and process HTML forms with Formmail or something.....

i dont know what kind of network you have there and i guess you cant talk much about it, but this would be pretty simple solution and wouldnt require you to even touch main server... you can even run that server on your own computer (offcourse if such solution is possible given where you work).



if i am wrong.... please someone correct me.:?:
 
If you can't run a web-server then have you MS Access installed? You could create a very simple database (one table with an auto-number primary key) to store the information and then an Access Forms front end for inputting the data. You could then dump the results to Excel, CSV or a text-file.

I could also write you a stand-alone C# application (if you have the .NET framework installed) but this would be a bit time consuming!
 
heh... there are many solutions possible, but i am not sure what he is allowed to do and even more what he is allowed to tell us he can do.... pretty tricky.
 
Put a WAMPserver on the PC. That way, you have Apache + PHP + MySQL running on it within a minute. You can even do it without installing anything, if that's not allowed.

As for the data, if MySQL is too hard to access directly, you can have the PHP sript dump the whole database to a CSV file (comma separated textfile) after each update. Or give your boss a login button and use a html page to display the data.
 
This is sad, but I swear it occurred to me in my sleep last night that I might be able to use Diplo's VB script by placing this html document that's on a local network drive by placing the file and share location in the browser's local intranet trusted sites. I could push this configuration via a GPO to all workstations for the building and this should get around the ActiveX issue. I'll have to try it on my own machine once I get to work, and if Diplo's script works then worry about ways of making the information from the form written in a clear, easy-to-read manner. Not sure if I want to append to the same file or have the form create a new file each time someone in the organization submits feedback so that the director can see the date of the file creation for each submittal. Diplo's script looks like it'll append.

And running any form of a web server would require an incredibly lengthy, painful process of having it blessed by the base's IA office, with the end result probably being told that adequate justification doesn't exist.
 
Last edited by a moderator:
Good idea, John. I can modify the script to write to separate files if you wish? Would just have to come up with a scheme for uniquely naming the files (eg. timestamp). Just gimme a shout if you need any help :)
 
Had a meeting with the director first thing this morning. She prefers the feedback to be via e-mail since her former organization had this setup for her. Her old organization also has an Apache webserver (I know their main admin) to run scripts from. So I'm going to sell her on the local form, so long as I can get it to work.
 
John Reynolds said:
Had a meeting with the director first thing this morning. She prefers the feedback to be via e-mail since her former organization had this setup for her. Her old organization also has an Apache webserver (I know their main admin) to run scripts from. So I'm going to sell her on the local form, so long as I can get it to work.

that would be prolly the best solution. WAMP server is really great (i use it for development) and easy to setup. this way you can have one computer as server for processing forms, while not messing with main server and PHP is really easy to work with...

it all depends how your form needs to work.... anonymous or you need to track who sent it? or just make it work on given IP range?


EDIT :: i am kinda noobish with PHP, but managed to make some sites ;)

EDIT 2 :: i guess you might have some spare parts around or old computers noone uses, so it would be possible to make small dedicated server that would run Apache and would be on 24/7
 
Last edited by a moderator:
This might be a stupid question, but using the html Form tags, would a CGI script sitting on a local network share work if the form tag read something like <form method=post action="/network share/script.cgi">?

I'm having trouble getting Diplo's VB script to work with my ActiveX configuration mandates. Only tested on my own workstation so far. It'll work if I enable running ActiveX controls and plug-ins, but haven't gotten it to work with that security setting disabled.

Edit: if I go the form route for this anonymous feedback I'm also going to avoid all formatting or page layout using HTML to force myself to learn more CSS.
 
2 things....

learning CSS fully requires lots of time and you shouldnt bother yourself right now with it.. unless you just want to set looks of form via CSS.

it should be <form method="POST" action="_Apache_server_IP">
that way everytime someone uses the form it will send request to local network and your own Apache server.


Edit: if I go the form route for this anonymous feedback I'm also going to avoid all formatting or page layout using HTML to force myself to learn more CSS.

learning CSS (depending on what you want to do) is REALLY tricky and takes lots of times. specially when you have to do it for IE which isnt W3C compliant.

IMO, forget CSS for now, cause it wont do you any good and concentrate on form....


(i can give you in PM some really good CSS resource links, but learning curve is really high and if u wanna this done in time, stay with tables........ and maybe later move to CSS based site) or just use CSS to define table cells which would be start....
 
John Reynolds said:
This might be a stupid question, but using the html Form tags, would a CGI script sitting on a local network share work if the form tag read something like <form method=post action="/network share/script.cgi">?
Not without that directory sitting somewhere under a webserver. This is basically your whole problem - if you don't have a webserver then you can't post data to a CGI script.

To be frank, if you can't install a webserver and you can't get ActiveX to work then I can't see how you can do it from HTML forms.
I'm having trouble getting Diplo's VB script to work with my ActiveX configuration mandates. Only tested on my own workstation so far. It'll work if I enable running ActiveX controls and plug-ins, but haven't gotten it to work with that security setting disabled.
I don't really use IE myself but can you add the site (or, in your case, file) to trusted sites? Tools > Internet Options > Security ?
Edit: if I go the form route for this anonymous feedback I'm also going to avoid all formatting or page layout using HTML to force myself to learn more CSS.
Personally I would recommend learning CSS if you have the time as it gives you much more control and flexibility over layout plus it separates style from content, meaning you can change the look of a site easily without effecting the content. For an idea of what you can do with CSS and XHTML 1.1 Strict then have a gander at my website - http://www.diplo.co.uk/ Try changing the 'skin' (left-hand drop-down menu) which changes the CSS but not the content.
 
Diplo said:
Not without that directory sitting somewhere under a webserver. This is basically your whole problem - if you don't have a webserver then you can't post data to a CGI script.

I thougth as much. Bummer.

To be frank, if you can't install a webserver and you can't get ActiveX to work then I can't see how you can do it from HTML forms.
I don't really use IE myself but can you add the site (or, in your case, file) to trusted sites? Tools > Internet Options > Security ?

I messed around with adding the file to the local intranet trusted sites but I only had a few minutes before a meeting. Got it to work several times, actually, but didn't have time to double-check IE security settings to make sure I wasn't violating mandated settings. But I'm fairly confident I can get it to work without getting my hands smacked during the next IA scan of my subnet and then configure IE for all workstations in my dept. via a GPO.

Personally I would recommend learning CSS if you have the time as it gives you much more control and flexibility over layout plus it separates style from content, meaning you can change the look of a site easily without effecting the content. For an idea of what you can do with CSS and XHTML 1.1 Strict then have a gander at my website - http://www.diplo.co.uk/ Try changing the 'skin' (left-hand drop-down menu) which changes the CSS but not the content.

Agreed. Plain HTML is just too limited for page layout. I'll check out your site later tonight. Thanks again for all your help.

Edit: Also, Diplo, what's a really good online resource for learning VBScript for a complete newb like me? I looked over your code and can understand the function/purpose of each line, but I'm not sure I could tailor it much without increasing my understanding.
 
Last edited by a moderator:
John Reynolds said:
Edit: Also, Diplo, what's a really good online resource for learning VBScript for a complete newb like me? I looked over your code and can understand the function/purpose of each line, but I'm not sure I could tailor it much without increasing my understanding.
This one from w3schools seems ok. Hit # 1 in my search. There's also hit # 2 and hit # 5, etc. The web is full of 'em. ;) :smile:
 
John Reynolds said:
Edit: Also, Diplo, what's a really good online resource for learning VBScript for a complete newb like me? I looked over your code and can understand the function/purpose of each line, but I'm not sure I could tailor it much without increasing my understanding.
To be honest VBScrtipt is a pretty horrible language and hopefully will be consigned to history soon! However, if you wish to learn it then here's a few useful sites:

Windows Scripting Documentation - This is compiled help-file (chm) you can download that is the official reference for VBScript. It won't help you learn but it's an invaluable reference point for the language. The same thing can be found online at MSDN here.

Apart from ones DarN mentions I'd also have a look at:

MSDN Scripting Resources

VBScript Tutorial

VBScript Forum

NB. Don't make the mistake of confusing ASP with VBScript. You can use VBScript to write ASP scripts but to run ASP you need the IIS webserver.

I'll be around if you have any questions :)
 
Back
Top