<h2>Please Enter contact information in the form below so we may contact you about advertising.</h2> <table border="1" width="100%"> <tr> <td width="18%">Name:</td> <td width="82%"><input type="text" name="name" size="40"></td> </tr> <tr> <td width="18%">Email Address:</td> <td width="82%"><input type="text" name="emailaddress" size="40"></td> </tr> <tr> <td width="18%">Phone Number:</td> <td width="82%"><input type="text" name="phonenumber" size="40"></td> </tr> <tr> <td width="18%">Comments</td> <td width="82%"> </td> </tr> <tr> <td colspan="2" width="100%"><textarea rows="6" name="comments" cols="58"></textarea></td> </tr> </table> <p> </p> <p><input type="submit" value="Submit" name="btnSubmit"><input type="reset" value="Reset" name="B2"></p> </form> </BODY>
</html>
<% End Sub %>
3 of 3 subs that is used in this example This procedure does the server-side code to insert a record and send an email. Then it redirects back to the form with one request.querystring variable to notify the Thank you page to be displayed.
<% Sub DoRecords() %>
'Note that I'm using an include file for my connection string, sense all server-side processing that needs a database connection is inside this sub that is where I place the connection string. You could easily put a DSN Entry, DSN-Less entry in here too.
<!--#include file="conn.asp"--> <% dim strconn dim conn dim rs
'Builds the body of the Message strBody = "A request for some info about your site" & chr(10) & chr(10) strBody = strBody & "Name: " & request("Name") & chr(10) strBody = strBody & "EmailAddress: " & request("Emailaddress") & chr(10) strBody = strBody & "PhoneNumber: " & request("PhoneNumber") & chr(10) strBody = strBody & "Comments: " & chr(10) & request("comments")
'Mails a copy of this request to the someone
set objNewMail = server.CreateObject("CDONTS.NewMail") objNewMail.From = "ASPFree.com" objNewMail.To = "someone@aspfree.com" objNewMail.BCC = "someone@aspfree.com" objNewMail.Subject = "A Simple form to collect info" objNewMail.Body = strBody objNewMail.Send set objNewMail = Nothing response.redirect "ads.asp?strMessage=Thanks" End Sub
%> <%
This is where the real logic is done.
'This If statement displays the Intro Page If request("btnSubmit") = "" and request("strMessage") = "" Then call IntroPage() End If
This if calls the DoRecords() Sub to process the form values If request("btnSubmit") = "Submit" Then call DoRecords() End If
This if processes the Thank you page after the form was submitted if request("strMessage") <> "" Then call Thanks() End If