Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    May 2009
    Posts
    13
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Writing To A TextFile or sending data to file

    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
    Last edited by druss016; 06-18-2009 at 12:10 AM.

  • #2
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,073
    Thanks
    38
    Thanked 498 Times in 492 Posts

    Lightbulb

    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.


    Good Luck!

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,155
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    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.

  • #4
    New Coder
    Join Date
    May 2009
    Posts
    13
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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.

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,155
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    Well, the ASP code is trivial, as I said:
    Code:
    <%
    qt = Chr(34) ' the quote mark
    
    Function clean( name )
        clean = qt & Replace( Request(name), qt, "''" ) & qt
    End Function
    
    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.Close
    outfile = 0
    fso = 0
    Response.End
    %>
    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.

    Done.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •