home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / aspgue1a / sign.asp < prev   
Encoding:
Text File  |  1999-05-22  |  9.5 KB  |  302 lines

  1. <html>
  2. <head>
  3. <title>My Guestbook</title>
  4. <!-- scripting , html copyright 1998 Kathi O'Shea ------->
  5. <!-- email info@web-savant.com for custom web development --->
  6. <!-- see readme.txt in zip file for modification and ---->
  7. <!-- redistribution info -------------------------------->
  8. </head>
  9. <body bgcolor="black" text="#C5BE60" topmargin=0 leftmargin=0>
  10. <center>
  11. <%
  12. Flag = request.form("Flag")
  13. If IsEmpty(Flag) or Flag = "" then
  14. %>
  15. <font face="times new roman">
  16. <i><h1>Sign My Guestbook</h1></i>
  17.     <font face="arial" size=2>
  18.      <b><i>Note:</i> * indicates a required field</b>
  19.     </font>
  20.  
  21. </font>
  22. <p> 
  23. <table width=500 border=0>
  24.   <tr>
  25.     <td width=100>
  26.     <font face="arial" size=2>
  27.     <b>*Name:</b>
  28.     </font>
  29.     </td>
  30.  
  31.     <td width=400>
  32.     <form action="sign.asp" method="post">
  33.     <input type="text" name="Name" size=30>
  34.     </td>
  35.   </tr>
  36.   
  37.   <tr>
  38.     <td width=100>
  39.     <font face="arial" size=2>
  40.     <b>*City:</b> 
  41.     </font>
  42.     </td>
  43.     
  44.     <td width=400><input type="text" name="City" size=30></td>
  45.   </tr>
  46.   
  47.   <tr>
  48.     <td width=100>
  49.     <font face="arial" size=2>
  50.     <b> State:</b> 
  51.     </font>
  52.     </td>
  53.     
  54.     <td width=400><input type="text" name="State" size=30></td>
  55.   </tr>
  56.  
  57.   <tr>
  58.     <td width=100>
  59.     <font face="arial" size=2>
  60.     <b>*Country:</b>
  61.     </font>
  62.     </td>
  63.     
  64.     <td width=400><input type="text" name="Country" size=30></td>
  65.   </tr>
  66.  
  67.   <tr>
  68.     <td width=100>
  69.     <font face="arial" size=2>
  70.     <b> Email:</b> 
  71.     </font>
  72.     </td>
  73.     
  74.     <td width=400><input type="text" name="Email" size=30></td>
  75.   </tr>
  76.  
  77.   <tr>
  78.     <td width=100>
  79.     <font face="arial" size=2>
  80.     <b> URL:</b> 
  81.     </font>
  82.     </td>
  83.     
  84.     <td width=400><input type="text" size=30 name="URL" value="http://"></td>
  85.   </tr>
  86.  
  87.   <tr>
  88.     <td valign="top" width=100>
  89.     <font face="arial" size=2>
  90.     <b>Comments:</b> 
  91.     </font>
  92.     </td>
  93.     
  94.     <td width=400>
  95.     <textarea name="Comments" cols=30 rows=5 wrap="virtual">
  96.     </textarea>
  97.     </td>
  98.   </tr>
  99.  
  100.   <tr>
  101.     <td width=100> </td>
  102.     <td width=400><br>
  103.     <input type="submit" value="Submit">
  104.     <input type="hidden" name="Flag" value=1>
  105.      <input type="reset" value="Clear"></form>
  106.     </td>
  107.   </tr>
  108.  
  109. </table>
  110. <%
  111. End If
  112. If Flag = 1 then
  113.     If IsEmpty(request.form("Name")) or request.form("Name")="" then
  114.         response.write "<center><font face='arial' size=4>"
  115.         response.write "<p><br><b>You must enter a name.</b></font>"
  116.         response.write "<form>"
  117.         response.write "<input type='button' value='Retry' onclick=history.back()>"
  118.         response.write "</form>"
  119.         response.end
  120.     Else
  121.         Name = request.form("Name")
  122.     End If
  123.  
  124.     If IsEmpty(request.form("City")) or request.form("City")="" then
  125.         response.write "<center><font face='arial' size=4>"
  126.         response.write "<p><br><b>You must enter a City.</b></font>"
  127.         response.write "<form>"
  128.         response.write "<input type='button' value='Retry' onclick=history.back()>"
  129.         response.write "</form>"
  130.         response.end
  131.     Else
  132.         City = request.form("City")
  133.     End If
  134.  
  135.     ' we won't require a state
  136.     State = request.form("State")
  137.  
  138.     If IsEmpty(request.form("Country")) or request.form("Country")="" then
  139.         response.write "<center><font face='arial' size=4>"
  140.         response.write "<p><br><b>You must enter a Country.</b>"
  141.         response.write "</font><form>"
  142.         response.write "<input type='button' value='Retry' onclick=history.go(-1)>"
  143.         response.write "</form>"
  144.         response.end
  145.     Else
  146.         Country = request.form("Country")
  147.     End If
  148.     Email = request.form("Email")
  149.         If request.form("URL")="http://" then
  150.            URL = ""
  151.         Else
  152.            URL = request.form("URL") 
  153.         End If
  154.     If IsEmpty(request.form("Comments")) or request.form("Comments")="" or request.form("Comments")="    " then
  155.         response.write "<center><font face='arial' size=4>"
  156.         response.write "<p><br><b>Don't forget to enter your comments!</b>"
  157.         response.write "</font><form>"
  158.         response.write "<input type='button' value='Retry' onclick=history.go(-1)>"
  159.         response.write "</form></center>"
  160.         response.end
  161.     Else
  162.         Comments = request.form("Comments")
  163.         Comments = Replace(Comments, Chr(34), "''")
  164.         Comments = Replace(Comments, vbCrLf, "<br>")
  165.     End If
  166.     Flag = request.form("Flag")
  167.  
  168. %>
  169. <table width=400 border=0>
  170.   <tr>
  171.     <td width=400>
  172.      <font face="arial" size=2>
  173.      <br>Here is the information you're submitting. If you would like to 
  174.      make changes, please use the appropriate button below, or use the other
  175.      button to submit this entry as it is.
  176.      <br>
  177.      <br><b>Name:</b> <%= Name %>
  178.      <br><b>City: </b> <%= City %>
  179.      <br><b>State: </b> <%= State %>
  180.      <br><b>Email: </b> <%= Email %>
  181.      <br><b>URL: </b> <%= URL %>
  182.      <p><b>Comments: </b> <%= Comments %>
  183.     <form action="sign.asp" method="post">
  184.     <input type="hidden" name="Name" value="<%= Name %>">
  185.     <input type="hidden" name="City" value="<%= City %>">
  186.     <input type="hidden" name="State" value="<%= State %>">
  187.     <input type="hidden" name="Country" value="<%= Country %>">
  188.     <input type="hidden" name="Email" value="<%= Email %>">
  189.     <input type="hidden" name="URL" value="<%= URL %>">
  190.     <input type="hidden" name="Comments" value="<%= Comments %>">
  191.     <input type="hidden" name="Flag" value=2>
  192.     <input type="submit" value="Yes, Submit it!"> 
  193.     <input type="button" value="Let's Try Again" onClick="history.go(-1)">
  194.     </form></font>
  195.     </td>
  196.   </tr>
  197. </table>
  198. <%
  199. End If
  200. If Flag = 2 then
  201.     Today = Now()
  202.         Name = request.form("Name")
  203.         Name = Replace(Name, "'", "''")
  204.         Name = Replace(Name, Chr(34), "''")
  205.         City = request.form("City")
  206.         City = Replace(City, "'", "''")
  207.         State = request.form("State")
  208.         Country = request.form("Country")
  209.         Country = Replace(Country, "'", "''")
  210.     Email = request.form("Email")
  211.     URL = request.form("URL")
  212.     Comments = request.form("Comments")
  213.     Comments = Replace(Comments, "'", "''")
  214.     ' ok now we've got our data so let's ship it off to the database
  215.     set conn = server.createobject("adodb.connection")
  216.     ' **** change DSN name if you're using a DSN and you've named it differently
  217.     'conn.open "guestbook"
  218.     ' **** DSN-less connection: comment out above line and uncomment the 
  219.     ' **** Code between "Begin" and "End"
  220.     ' **** BEGIN DSN-LESS CONNECTION CODE 
  221.     DSNtemp="DRIVER={Microsoft Access Driver (*.mdb)}; "
  222.     DSNtemp=dsntemp & "DBQ=" & server.mappath("/guestbook.mdb")
  223.     conn.Open DSNtemp
  224.     ' **** END OF DSN-LESS CONNECTION CODE
  225.     ' **** Note: If using a DSN-less connection, make sure to change server.mappath above to 
  226.     ' **** reflect the actual location of the guestbook database file.
  227.     ' **** The above will work if the database file is at the webserver root.
  228.     ' **** See readme.txt for further information
  229.     ' **** the following line would be used ONLY if you use a system DSN!
  230.     ' conn.Open "guestbook"
  231.     
  232.     SQLstmt = "INSERT INTO Guestbook (Name,City,State,Country,Email,URL,Comments)"
  233.     SQLstmt = SQLstmt & " VALUES (" 
  234.     SQLstmt = SQLstmt & "'" & Name & "',"
  235.     SQLstmt = SQLstmt & "'" & City & "',"
  236.     SQLstmt = SQLstmt & "'" & State & "',"
  237.     SQLstmt = SQLstmt & "'" & Country & "',"
  238.     SQLstmt = SQLstmt & "'" & Email & "',"
  239.     SQLstmt = SQLstmt & "'" & URL & "',"
  240.     SQLstmt = SQLstmt & "'" & Comments & "'"
  241.     SQLstmt = SQLstmt & ")"
  242.  
  243.     Set RS = conn.execute(SQLstmt)
  244.     If err.number>0 then
  245.            response.write "VBScript Errors Occured:" & "<P>"
  246.         response.write "Error Number=" & err.number & "<P>"
  247.         response.write "Error Descr.=" & err.description & "<P>"
  248.         response.write "Help Context=" & err.helpcontext & "<P>" 
  249.         response.write "Help Path=" & err.helppath & "<P>"
  250.         response.write "Native Error=" & err.nativeerror & "<P>"
  251.         response.write "Source=" & err.source & "<P>"
  252.         response.write "SQLState=" & err.sqlstate & "<P>"
  253.        end if
  254.        IF conn.errors.count> 0 then
  255.         response.write "Database Errors Occured" & "<P>"
  256.         response.write SQLstmt & "<P>"
  257.            for counter= 0 to conn.errors.count
  258.             response.write "Error #" & conn.errors(counter).number & "<P>"
  259.             response.write "Error desc. -> " & conn.errors(counter).description & "<P>"
  260.            next
  261.        else
  262.         response.write "<br><br><font face='arial' size=4><b>"
  263.         response.write "Thank you! Your entry has been added.</font><p>"
  264.         response.write "<font face='arial' size=2>"
  265.         response.write "<a href='default.asp'>View Guestbook</a>"
  266.        end if
  267.        Conn.Close
  268.     Set conn = nothing
  269.     ' *****************************************************************
  270.     ' The following section of code sends email to the guestbook owner
  271.     ' when somebody signs the guestbook. If you don't want this feature,
  272.     ' just remove this block. Please note that this will ONLY work on
  273.     ' NT SERVER with built-in SMTP!! On other systems, please see 
  274.     ' http://www.attitude.com/users/kathi/asp/tools.html for a list of
  275.     ' components, including email components
  276.     ' ******************************************************************
  277.     Set Mail = CreateObject("CDONTS.Newmail")
  278.     ' get the sender's address, and if empty, put your own
  279.     If request("email")="" then
  280.         Sender = "info@web-savant.com"     ' put your email address here
  281.     Else
  282.         Sender = request("email")
  283.     End If
  284.     Mail.From = Sender
  285.     Mail.To = "you@yourdomain.com"       ' put YOUR email address here
  286.     Mail.Subject = "New Guestbook Entry" ' you can change this to whatever you'd like
  287.     Msg = "Name: " & request("name") & Chr(10)
  288.     Msg = Msg & "City: " & request("city") & Chr(10)
  289.     Msg = Msg & "State: " & request("State") & Chr(10)
  290.     Msg = Msg & "Country: " & request("Country") & Chr(10)
  291.     Msg = Msg & "URL: " & URL & Chr(10)
  292.     Msg = Msg & "Comments:" & Chr(10)
  293.     Msg = Msg & request("Comments")
  294.     Mail.Body = Msg
  295.     Mail.Send
  296.     Set Mail = Nothing
  297.  
  298. End If
  299. %>
  300. </center>
  301. </body>
  302. </html>