<html>
<head>
<title>Survey</title>
</head>
<body onload="StartUp();">
<center>
<form name="frmInfo" method="post" action="Thanks.asp">
<input type="hidden" name="txtAction" value="">
<table width="300px" border="1" cellspacing="5" cellpadding="10" bgcolor="#a9b9cc">
<tr>
<td>
<table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#a9b9cc">
<tr>
<td colspan=2 align="center"><b>Contact Blue Sand Software</b><hr></td>
</tr>
<tr>
<td colspan=2> </td>
</tr>
<tr>
<td nowrap>First Name:</td>
<td nowrap><input type="text" size="30" name="txtFirstName"></td>
</tr>
<tr>
<td nowrap>Last Name:</td>
<td nowrap><input type="text" size="30" name="txtLastName"></td>
</tr>
<tr>
<td nowrap>Email Address:</td>
<td nowrap><input type="text" size="30" name="txtEMail"></td>
</tr>
<tr>
<td colspan=2> </td>
</tr>
<tr>
<td nowrap colspan="2">I am interested in the following services:</td>
</tr>
<tr>
<td nowrap colspan="2">
<input type="checkbox" name="chkTraining"> Training
</td>
</tr>
<tr>
<td nowrap colspan="2">
<input type="checkbox" name="chkConsulting"> Consulting
</td>
</tr>
<tr>
<td nowrap colspan="2">
<input type="checkbox" name="chkMentoring"> Mentoring
</td>
</tr>
<tr>
<td colspan=2> </td>
</tr>
<tr>
<td nowrap colspan="2">
<input type="checkbox" name="chkReceiveEMails">
Yes, I want to receive updates and offers from via EMail.
</td>
</tr>
<tr>
<td colspan=2> </td>
</tr>
<tr>
<td colspan="2" align="center" nowrap>Comments / Additional Interest:</td>
</tr>
<tr>
<td colspan="2" nowrap><textarea rows="5" cols="40"
name="txtComments"></textarea></td>
</tr>
<tr>
<td colspan="2" align="center">
<br><input type="button" value="Submit" name="btnSubmit"
onclick="SubmitPage();">
<input type="reset" value="Clear" name="txtReset">
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</center>
</body>
</html>
Figure 6 Validating Visitor Input
<script language="javascript">
function SubmitPage()
{
//--- If the required fields are entered...
if (Validate())
{
//--- Submit the page
document.frmInfo.txtAction.value = "Submit";
document.frmInfo.submit();
}
}
function Validate()
{
//--- Make sure the First Name was entered
if(document.frmInfo.txtFirstName.value.length == 0){
document.frmInfo.txtFirstName.focus();
document.frmInfo.txtFirstName.select();
alert("You must enter a first name to continue.");
return false;
}
//--- Make sure the Last Name was entered
if(document.frmInfo.txtLastName.value.length == 0){
document.frmInfo.txtLastName.focus();
document.frmInfo.txtLastName.select();
alert("You must enter a last name to continue.");
return false;
}
//--- Make sure the EMail Address was entered
if(document.frmInfo.txtEMail.value.length == 0){
document.frmInfo.txtEMail.focus();
document.frmInfo.txtEMail.select();
alert("You must enter an EMail address to continue.");
return false;
}
return true;
}
function StartUp()
{
//--- Set the focus to the First Name textbox
document.frmInfo.txtFirstName.focus();
}
</script>
Figure 7 Thanks.asp
<%@LANGUAGE=VBScript%>
<%
Option Explicit
'--------------------------------------------------------------
'--- DECLARE ALL VARIABLES
'--------------------------------------------------------------
dim booMentoring
dim booTraining
dim booConsulting
dim booDistributionList
dim lngVisitorID
dim objConn
dim objRS
dim objEMail
dim strBody
dim strFirstName
dim strLastName
dim strEMail
dim strComments
dim strSQL
'--------------------------------------------------------------
If Request("txtAction") = "Submit" then
'--------------------------------------------------------------
'--- Retrieve the parameters passed in from Survey.htm.
'--------------------------------------------------------------
strFirstName = Request("txtFirstName")
strLastName = Request("txtLastName")
strEMail = Request("txtEMail")
booMentoring = Request("chkTentoring")
booTraining = Request("chkTraining")
booConsulting = Request("chkConsulting")
strComments = trim(Request("txtComments"))
booDistributionList = Request("chkReceiveEMails")
if booDistributionList = "on" then booDistributionList =-1 else booDistributionList=0
if booMentoring ="on" then booMentoring=-1 else booMentoring=0
if booTraining ="on" then booTraining=-1 else booTraining=0
if booConsulting ="on" then booConsulting=-1 else booConsulting=0
'--------------------------------------------------------------
'--- Declare and open a connection to the Survey database.
'--------------------------------------------------------------
set objConn = Server.CreateObject("ADODB.Connection")
set objRS = Server.CreateObject("ADODB.Recordset")
objConn.Open "CDONTS"
'--------------------------------------------------------------
'--- Check if this person has visited before.
'--------------------------------------------------------------
strSQL = "SELECT VisitorID, OnDistributionList FROM Visitor"
strSQL = strSQL & " WHERE EMailAddress = '" & strEMail & "'"
set objRS = objConn.Execute(strSQL)
if objRS.EOF then
'--------------------------------------------------------------
'--- This is this person's first visit, so we add them to
'--- the Visitor table.
'--------------------------------------------------------------
objRS.Close
strSQL = "INSERT INTO Visitor (FirstName, LastName, EMailAddress, OnDistributionList)"
strSQL = strSQL & " VALUES"
strSQL = strSQL & " ('" & strFirstName & "', '" & strLastName & "','" & strEMail & "',"
strSQL = strSQL & booDistributionList & ")"
strSQL = strSQL & ";SELECT @@IDENTITY"
set objRS = objConn.Execute(strSQL)
'--------------------------------------------------------------
'--- Here, we retrieve the primary key of the new visitor.
'--------------------------------------------------------------
set objRS = objRS.NextRecordset
lngVisitorID = objRS(0)
else
lngVisitorID = objRS("VisitorID")
if objRS("OnDistributionList") <> booDistributionList then
'--------------------------------------------------------------
'--- Update the visitor's distribution list status.
'--------------------------------------------------------------
strSQL = "UPDATE Visitor SET OnDistributionList = " & booDistributionList
strSQL = strSQL & " WHERE EMailAddress = '" & strEMail & "'"
objConn.Execute strSQL
end if
objRS.Close
end if
'--------------------------------------------------------------
'--- Insert this visit into the Visit table.
'--------------------------------------------------------------
strSQL = "INSERT INTO Visit (VisitorID, Comments, Mentoring, Consulting, Training, NewMail)"
strSQL = strSQL & "VALUES (" & lngVisitorID & ",'" & strComments & "',"
strSQL = strSQL & booMentoring & "," & booConsulting & "," & booTraining & ", 1)"
objConn.Execute strSQL
objConn.Close
set objConn = nothing
'--------------------------------------------------------------
'--- Send out the email to the visitor
'--------------------------------------------------------------
set objEMail = Server.CreateObject("CDONTS.NewMail")
objEMail.To = strEMail
objEMail.From = "info@bluesand.com"
objEMail.subject = "Thank you for your inquiry."
strBody = strFirstName & "," & vbCrLf & vbCrLf & vbTab
strBody = strBody & "Your information is being processed."
strBody = strBody & vbCrLf & vbCrLf & "Thank you, Blue Sand Software."
strBody = strBody & vbCrLf & vbCrLf & "http://www.bluesand.com "
objEMail.body = strBody
objEMail.send
set objEMail = nothing
'--------------------------------------------------------------
'--- Send out the email to the administrator
'--------------------------------------------------------------
set objEMail = server.CreateObject("CDONTS.NewMail")
objEMail.To = "johnp@bluesand.com"
objEMail.From = strEMail
objEMail.subject = "Inquiry from " & strFirstName & " " & strLastName
strBody = vbCrLf & vbCrLf & "Mentoring:" & booMentoring
strBody = strBody & vbCrLf & "Consulting: " & booConsulting
strBody = strBody & vbCrLf & "Training: " & booTraining
strBody = strBody & strComments
objEMail.body = strBody
objEMail.send
set objEMail = nothing
End If
%>
<html>
<head>
<title>Thank You</title>
</head>
<body>
<center>
<table width="300px" border="1" cellspacing="5" cellpadding="10" bgcolor="#a9b9cc">
<tr>
<td>
<table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#a9b9cc">
<tr>
<td colspan="4" align=center>
Your request for information has been sent to Blue Sand Software. Thank you.
</td>
</tr>
</table>
</td>
</tr>
</table>
</center>
</body>
</html>
Figure 8 SendMassEmail.asp
<%@ Language=VBScript %>
<%Option Explicit%>
<%
dim objConn
dim objEMail
dim objRS
dim strSQL
If Request("txtAction") = "SendMail" then
set objConn = Server.CreateObject("ADODB.Connection")
set objRS = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT EMailAddress FROM Visitor "
strSQL = strSQL & " WHERE OnDistributionList = 1"
objConn.Open "CDONTS"
set objRS = objConn.Execute(strSQL)
do while not objRS.EOF
set objEMail = Server.CreateObject("CDONTS.NewMail")
objEMail.To = objRS("EMailAddress")
objEMail.From = Request("txtFrom")
objEMail.Subject = Request("txtSubject")
objEMail.Body = Request("txtBody")
objEMail.Send
set objEMail = nothing
objRS.MoveNext
loop
objRS.Close
objConn.Close
set objRS = nothing
set objConn = nothing
End If
%>
<html>
<head>
<title>Mail Has Been Sent</title>
</head>
<body>
<center>
<table width="300px" border="1" cellspacing="5" cellpadding="10" bgcolor="#a9b9cc">
<tr>
<td>
<table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#a9b9cc">
<tr>
<td colspan="4" align=center>
<!-- #INCLUDE FILE="Header.txt" -->
<br>
</td>
</tr>
<tr>
<td colspan="4" align=center>
Your EMail message has been sent successfully to the distribution list.
</td>
</tr>
</table>
</td>
</tr>
</table>
</center>
</body>
</html>