Request  info and save it to a file  (.asp)

In this example we will use a form to request information to our visitors and we will saved that information to a file. As we may get information from different visitors, in this example we will create a new file each time we get info from a new visitor. The script will create all necessary folders and files automatically. This script has been generated specifically for you (in your next visit the code will be prepared to save the information from your visitors in a different place within your server)
  • All the information obtained from our form will be saved in  a subdirectory within cgi-bin folder (p.e.: "c:\mydir\cgi-bin\messages852398\"), and the information will be saved in a ".txt" file (p.e.: "c:\mydir\cgi-bin\messages852398\1.txt"). That way we will prevent other users form getting information without permission (a ".txt" file located in the cgi-bin directory is not accessible by the client). The subdirectory necessary to save the information will be create automatically.
  • We will also need a file with a number as its unique content .This file will be used as a counter, and each time a visitor fills in our form the information provided will be save to a file (for example information from the first visitor will be save in  file  "1.txt", information from the second one in "2.txt"...). The counter file will be create automatically. 
This script will allow us to add any kind and number of input fields within the form, so that we may use the same response page for all forms in our site ("saveinfo.asp" may be used to save information from "form1.html", "form2.html" etc.)
 
 
form.html 
<FORM ACTION="saveinfo.asp" METHOD=post>

<!-- Your fields here -->

<INPUT TYPE=submit value="Submit">
</FORM>


 
 
saveinfo.asp
<%
Set fs = CreateObject("Scripting.FileSystemObject")

Folderpath=server.mappath("\") & "/cgi-bin/messages852398" 
Wcounter=Folderpath &"/counter.txt" 

Set fs = CreateObject("Scripting.FileSystemObject") 
    if fs.FolderExists(Folderpath) then 
        Set a = fs.OpenTextFile(Wcounter) 
        hits = Clng(a.ReadLine) 
        hits = hits + 1 
        a.close 
    else 
        Set a = fs.CreateFolder(Folderpath) 
        hits=1
    end if 

Set a = fs.CreateTextFile(Wcounter,True) 
a.WriteLine(hits) 
a.Close
Set fs=nothing 

Set fs = CreateObject("Scripting.FileSystemObject") 
Set a = fs.CreateTextFile(Folderpath & "\" & hits & ".txt") 
   For Each x In Request.Form
      a.WriteLine(x &": " & Request.Form(x))
   Next
a.Close 
Set a=nothing 
Set fs=nothing 
%> 

Thanks for providing the requested information<BR>
I will contact you very soon. 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
  • Lines 2-18. In case the folder where information will be saved does not exits, it will be create.  The counter file will be also create. If they already exits, the counter will be open, the content read to a variable named "hits", and increased by one. 
  • Lines 20-23. the value for variable h"hits" will be save in "counter.txt"  file in our folder. 
  • Lines 25-32, information provided  per input field will be saved to a file. The name of the file will be composed by the variable hits (a number) and ".txt"
  • Lines 34-35. Write here your response. 
    • The response may be a text, as in this example, 
    • You may redirect the visitor to a different page. The code will be this one:
      <% response.redirect("http://www.mysite.com") %>
    • You may include as a response page the content in a page within your site
       <!--#include virtual="/myresponse.html" --> 
I
In order to access the information saved to files we may use the script bellow. That way we will be able to access the information from all visitors in an unique page.  Access to information is password protected (Name and password to access the information are shown in line two. If the name and password are not correct the form will be send (Subroutine "Sendform ()"), and in case they are correct the info is send (Subroutine "Sendinfo ()"). 
 
getinfo.asp 
<% 
if request.form("name")="Peter" and request.form("password")="yes" then 
Sendinfo ()
else 
Sendform ()
end if 
%>

<% 
Sub Sendform() %> 

<FORM ACTION="getinfo.asp" METHOD=post>
Name: <input type=text name=name><br>
Password: <input type=password name=password><br>
<INPUT TYPE=submit value="Submit">
</FORM>

<% End Sub %>
 

<% 
Sub Sendinfo()

FolderToCheck = server.mappath("\") & "/cgi-bin/messages852398"

 Dim fs, f, f1, fc, s
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set f = fs.GetFolder(FolderToCheck)
 Set fc = f.Files
 

For Each f1 in fc
  Wfile=f1.name

Response.write("<hr><b>" & Wfile & "/" & "</b><p>")
   FiletoCheck=FolderToCheck  & Wfile
    Set a=fs.OpenTextFile(FiletoCheck)
     theinfo=a.ReadAll
Response.write("<pre>" & Theinfo & "</pre>")
Next
Response.write("<hr>Script provided by <a href=http://www.codedcode.com>codedcode.com</a>")

End sub
%>

On request we have create a new script which allows to delete messages after reading them
To get the script, choose a name and a password, and you will get the new version of the script in the response page. The name of the resulting script and location in your site is not limited.

Choose name

Choose password











   



MSN Nick Name



More Resources...





Most Viewed Services:
  1. HTML Tutorial
  2. XHTML Tutorial
  3. CSS Tutorial
  4. Javascript Tutorial
  5. DHTML Tutorial
  6. VB Script
  7. TCP/IP Tutorial
  8. ADO Tutorial
  9. MYSQL Tutorial
  10. ASP Tutorial
  11. AJAX Tutorial
  12. CFML Tutorial
  13. PHP Tutorial
  14. WML Tutorial
  15. FLASH Tutorial
  16. XML Tutorial
  17. RSS Tutorial
  18. SQL Tutorial
  19. HTML Articles
  1. Javascript Articles
  2. PHP Articles
  3. SEO Articles
  4. Web Design Articles
  5. SEO Tips
  6. Web Design Tips
  7. Articles
  8. CSS
  9. CSS Tips
  10. HTML Tips
  11. JAVASCRIPT Tips
  12. MYSQL Tips
  13. PHP Tips
  14. Money
  15. Tutorials
  16. Web Hosting



  • Home
  • Web Directory
  • Top Directoriers
  • Webmaster Directories
  • Contact
  • © Copyright 2006-2010 All Rights Reserved By CodeDcode.Com : HTML : RSS : TEXT : XML