View Full Version : Writing To A TextFile or sending data to file
06-18-2009, 12:58 AM
Hello, i have a widget which incllude html script, I am trying to send this widget to people that request it and allow them to use it in their own webpages....I am trying to figure out how to let the person enter information in the "form" and when they press the send button no screen pops up but the information is sent to a textfile in our public html directory....
or would that be asp
06-18-2009, 01:18 AM
Won't happen with JS directly. :(
I have used a program called 'formmail.cgi' in the past to write from HTML form input
to append to a specific server text file using JS, but that 'cgi' is server side, not client side code.
Most ISPs have it or a similar function.
06-18-2009, 01:39 AM
SInce you mentioned ASP...
If you really just want to save the info in a text file, that's easy with ASP.
Do you mean that each <form> creates a *new* text file? Or you have something like a ".csv" file that you want a new line/record appended to with each <form> submit??
I should warn you, though, that this kind of <form> is the idiot's delight of spammers and hackers everywhere: They will surely inundate you with thousands and thousands of bogus form submittals. If you are really going to do something like this, then AT A MINIMUM you should offer a CAPTCHA image that people who use your widget must include.
06-18-2009, 02:24 AM
yes, that would be helpful, and to create a new line to a text file upon each submit. so my widget on their page is assosiating with mine, and once they submit their page is not refreshed or no other page pops up from the form being submitted, im not worried really about spammers, i have hard code for that, what do you think is the best thing to do.
06-18-2009, 04:26 AM
Well, the ASP code is trivial, as I said:
qt = Chr(34) ' the quote mark
Function clean( name )
clean = qt & Replace( Request(name), qt, "''" ) & qt
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Set outfile = fso.OpenTextFile( Server.MapPath("./logfile.csv"), 8 ) ' 8 is append mode
outfile.writeline clean("field1") & "," & clean("field2") & "," & clean("field3")
outfile = 0
fso = 0
Note the use of Server.MapPath: The argument is the *relative* path to the data file you want to use.
I opted to use a ".csv" file, because then you could load it into Excel or Access (or most any DB) to make it more useful.
So that means that I put quotes around all the field values and commas between values. In order to ensure that there are no problem quotes in the field values, I replace any " with a pair of apostrophes. Choose your own poison.
I simply write one line to the file, consisting of all the "clean"ed fields from the <form> with commas between values.
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.