%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<% Option Explicit %>
<%
'=================================
'
'=================================
'Make sure this page is not cached
Response.Expires = -1
Response.ExpiresAbsolute = Now() - 2
Response.AddHeader "pragma","no-cache"
Response.AddHeader "cache-control","private"
Response.CacheControl = "No-Store"
'Set the response buffer to true as we maybe redirecting
Response.Buffer = True
' Declare Variables
Dim sRequestMethodGet, sRequestMethodPost, sScriptName, sHost
Dim bGoodFirstName, bGoodLastName, bGoodEmail, bGoodPhone, bGoodPost, bDisplayErrorMessage
Dim sFirstName, sLastName, sCompany, sEmail, sPhone, sApproximateSquareFootage, sNumberOfEmployees, sDaysPerServices, sMonthlyBudget, sOtherInformation
' Set Variables
sRequestMethodGet = UCase(Trim(Request.ServerVariables("REQUEST_METHOD"))) = "GET"
sRequestMethodPost = UCase(Trim(Request.ServerVariables("REQUEST_METHOD"))) = "POST"
sScriptName = Request.ServerVariables("SCRIPT_NAME")
sHost = "smtp.spruceusa.com"
' Set variables to check form fields
sFirstName = Trim(Mid(Request.Form("txtFirst_Name").Item,1,50))
sLastName = Trim(Request.Form("txtLast_Name").Item)
sCompany = Trim(Request.Form("txtCompany").Item)
sEmail = Trim(Request.Form("txtEmail").Item)
sPhone = Trim(Request.Form("txtPhone").Item)
sApproximateSquareFootage = Trim(Request.Form("txtApproximate_Square_Footage").Item)
sNumberOfEmployees = Trim(Request.Form("txtNumber_of_Employees").Item)
sDaysPerServices = Trim(Request.Form("txtDays_per_Services").Item)
sMonthlyBudget = Trim(Request.Form("txtMonthly_Budget").Item)
sOtherInformation = Trim(Request.Form("txtOther_Information").Item)
' Set boolean variables for valid/invalid form fields
If Not isValidName(sFirstName) Then bGoodFirstName = False Else bGoodFirstName = True
If Not isValidName(sLastName) Then bGoodLastName = False Else bGoodLastName = True
If Not isValidEmail(sEmail) Then bGoodEmail = False Else bGoodEmail = True
If Not isValidPhone(sPhone) Then bGoodPhone = False Else bGoodPhone = True
' Is form submission good?
bGoodPost = (bGoodFirstName AND bGoodLastName AND bGoodEmail AND bGoodPhone)
If Not bGoodPost Then bDisplayErrorMessage = True
' Initialize variables
If sRequestMethodGet Then
bGoodFirstName = True
bGoodLastName = True
bGoodEmail = True
bGoodPhone = True
bDisplayErrorMessage = False 'GoodPost = True
End If
%>
..:: Spruce Facilities Management ::.. Get a Quote!
<%
' Determine whether to display or process the form
If sRequestMethodGet Then
Call DisplayForm()
ElseIf sRequestMethodPost Then
Call ProcessForm()
Else
' are you supporting any other request methods?
End If
%>
:: Spruce Facilities Management ::(877) 577-7823 (1-877-5-SPRUCE)
254 East Grand Avenue, Suite 206, Escondido, CA 92025
69818 Camino Pacifico, Rancho Mirage, CA 92270
4533 MacArthur Boulevard, Suite 169, Newport Beach, CA 92660
Please provide your contact information and any other information you would like us to have. We will contact you within one
business day. You may also call our office (877) 577-7823 or email us.
* information is required
<%
End Sub
Sub ProcessForm()
' If for validates, then continue. Otherwise redisplay form
If bGoodPost = True Then
'Clean up user input
sFirstName = removeAllTags(sFirstName)
sFirstName = formatInput(sFirstName)
sLastName = removeAllTags(sLastName)
sLastName= formatInput(sLastName)
sCompany = removeAllTags(sCompany)
sCompany = formatInput(sCompany)
' Remove any single quotes as they should not be in email addresses
sEmail = Replace(sEmail, "'", "", 1, -1, 1)
sEmail = removeAllTags(sEmail)
sEmail = formatInput(sEmail)
sPhone = removeAllTags(sPhone)
sPhone = formatInput(sPhone)
sApproximateSquareFootage = removeAllTags(sApproximateSquareFootage)
sApproximateSquareFootage = formatInput(sApproximateSquareFootage)
sNumberOfEmployees = removeAllTags(sNumberOfEmployees)
sNumberOfEmployees = formatInput(sNumberOfEmployees)
sDaysPerServices = removeAllTags(sDaysPerServices)
sDaysPerServices = formatInput(sDaysPerServices)
sMonthlyBudget = removeAllTags(sMonthlyBudget)
sMonthlyBudget = formatInput(sMonthlyBudget)
sOtherInformation = removeAllTags(sOtherInformation)
sOtherInformation = formatInput(sOtherInformation)
'=================================
' Send Email
'=================================
Dim strHeader, strFooter
Dim ix, formElementName, formElementValue, prefix, fldName
'The header/footer for the email.
'Const strHeader = "Here are the results of the form:"
'Const strFooter = "Form mailer created by 4GuysFromRolla.com, 1999"
'Who does this go to?
Const strTo = "customerservice@spruceusa.com"
'This information is optional
Dim strFrom, strSubject, strRedirectURL, strBody
strFrom = Request.Form("txtEmail")
if Len(strFrom) = 0 then strFrom = strTo
strSubject = Request.Form("txtEmailSubject")
if Len(strSubject) = 0 then strSubject = "Get a Quote"
strRedirectURL = Request.Form("urlSendTo")
if Len(strRedirectURL) = 0 then strRedirectURL = "/"
strBody = strHeader & vbCrLf & vbCrLf
strBody = strBody & "FORM submitted at " & Now() & vbCrLf & vbCrLf
' Build Email Message Body from Form Elements
For ix = 1 to Request.Form.Count
formElementName = Request.Form.Key(ix)
formElementValue = Request.Form.Item(ix)
' what type of field was that on the form?
prefix = Left(formElementName,3)
' and throw away prefix to get actual field name
fldName = Mid(formElementName,4)
' but change periods to spaces for readability
fldName = Replace(fldName, "_"," ")
Select Case prefix
' if the prefix indicates this is a form field of interest...
Case "txt","sel","rad","rdo","cbo","lst","chk":
' if user didn't answer this question, say so...
if Len(formElementValue) = 0 then formElementValue = "UNANSWERED"
' then tack on the name of the field and the answer
strBody = strBody & (fldName & ": " & formElementValue & vbCrLf)
End Select
Next
' Footer
strBody = strBody & vbCrLf & strFooter
' Send email using ASPEmail
Dim Mail
Set Mail = Server.CreateObject("Persits.MailSender")
Mail.Host = sHost ' enter valid SMTP host
Mail.From = strFrom ' From address
Mail.FromName = sFirstName & " " & sLastName ' optional
Mail.AddAddress strTo
Mail.Subject = strSubject ' message subject
Mail.Body = strBody ' message body
Dim strErr, bSuccess
strErr = ""
bSuccess = False
'On Error Resume Next ' catch errors
Mail.Send ' send message
Set Mail = Nothing
If Err <> 0 Then ' error occurred
strErr = Err.Description
Response.Write(" Error: " & strErr & " ")
Else
bSuccess = True
' Redirect to thank you page
Response.Clear()
Response.Redirect strRedirectURL
End If
' Send email using CDONTS
'Dim objCDO
'Set objCDO = Server.CreateObject("CDONTS.NewMail")
'objCDO.To = strTo
'objCDO.From = strFrom
'objCDO.Subject = strSubject
'objCDO.Body = strBody
'objCDO.Send
'Set objCDO = Nothing
' Redirect to thank you page
'Response.Clear()
'Response.Redirect strRedirectURL
Else
' re-display the form with values pre-filled and problem fields highlighted
Call DisplayForm()
End If
End Sub
'=================================
' Functions
' Regular Expression functions from: http://aspzone.com/articles/173.aspx
'=================================
Function getValue(byval sImportant, byval sPassive)
' notice that we aren't checking for a valid value, just *any* value
If Not isEmpty(sImportant) Then
getValue = sImportant
Else
getValue = sPassive
End If
End Function
Function isValidName(byval sExpression)
' http://www.regexlib.com/REDetails.aspx?regexp_id=525
' ^[A-Za-zÀ-ÖØ-öø-ÿ '\-\.]{1,22}$ (Sample matches: Jill St. John|||Jørnç|||Mc O'Donald-Öztürk)
Dim objRegExp
Set objRegExp = New RegExp
objRegExp.Pattern = "^[A-Za-zÀ-ÖØ-öø-ÿ '\-\.]{1,22}$"
isValidName = objRegExp.Test(sExpression)
Set objRegExp = Nothing
End Function
Function isValidZip(byval sZip)
' http://www.regexplib.com/REDetails.aspx?regexp_id=342
' Allows Canadian, American and UK postal/zip codes. Allowing hyphens, periods, or spaces to separate.
' ^(\d{5}(( |-)\d{4})?)|([A-Za-z]\d[A-Za-z]( |-)\d[A-Za-z]\d)$
Dim objRegExp
Set objRegExp = New RegExp
objRegExp.Pattern = "^(\d{5}((|-)-\d{4})?)|([A-Za-z]\d[A-Za-z][\s\.\-]?(|-)\d[A-Za-z]\d)|[A-Za-z]{1,2}\d{1,2}[A-Za-z]? \d[A-Za-z]{2}$"
isValidZip = objRegExp.Test(sZip)
Set objRegExp = Nothing
End Function
Function isValidPhone(byval sExpression)
' http://www.regexlib.com/REDetails.aspx?regexp_id=530
Dim objRegExp
Set objRegExp = New RegExp
objRegExp.Pattern = "^[2-9]\d{2}-\d{3}-\d{4}$"
isValidPhone = objRegExp.Test(sExpression)
Set objRegExp = Nothing
End Function
Function isValidEmail(byval sEmail)
' ^(?:[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+\.)*[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+@(?:(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9\-](?!\.)){0,61}[a-zA-Z0-9]?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9\-](?!$)){0,61}[a-zA-Z0-9]?)|(?:\[(?:(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\]))$
Dim objRegExp
Set objRegExp = New RegExp
objRegExp.Pattern = "^[\w\.-]+@[\w\.-]+\.[a-zA-Z]+$"
isValidEmail = objRegExp.Test(sEmail)
Set objRegExp = Nothing
End Function
'=================================
' Strip all tags
'=================================
'Remove all tags for text only display (mainly for subject lines)
Private Function removeAllTags(ByVal strInputEntry)
'Remove all HTML scripting tags etc. for plain text output
strInputEntry = Replace(strInputEntry, "&", "&", 1, -1, 1)
strInputEntry = Replace(strInputEntry, "<", "<", 1, -1, 1)
strInputEntry = Replace(strInputEntry, ">", ">", 1, -1, 1)
strInputEntry = Replace(strInputEntry, "'", "", 1, -1, 1)
strInputEntry = Replace(strInputEntry, """", """, 1, -1, 1)
'Return
removeAllTags = strInputEntry
End Function
'=================================
' Format user input
'=================================
'Format user input function
Private Function formatInput(ByVal strInputEntry)
'Get rid of malicous code in the message
strInputEntry = Replace(strInputEntry, "", "", 1, -1, 1)
strInputEntry = Replace(strInputEntry, "