%@LANGUAGE="VBSCRIPT" %>
<%
const numFields = 6
dim errorArray()
redim preserve errorArray(numFields)
if request.form("isSubmitted") = "yes" then
title = request.form("title")
name1 = request.form("name1")
phone = request.form("phone")
email = request.form("email")
query = request.form("query")
details = request.form("details")
ErrorMsg = ""
dim re, results
set re = New RegExp
'Name
re.Pattern = "^[^0-9\/><\.,\\!\^\$\*\+\?@#%&\(\);:\[\]\{\}=""']+$"
re.Global = True
re.IgnoreCase = True
results = re.Test(name1)
if results then
errorArray(0) = "False"
else
errorArray(0) = "True"
ErrorMsg = ErrorMsg & "- Please enter your name. "
end if
'Telephone
'Formats a given 10 digit number into a nice looking phone number
Function FormatPhoneNumber(strNumber)
Dim strInput ' String to hold our entered number
Dim strTemp ' Temporary string to hold our working text
Dim strCurrentChar ' Var for storing each character for eval.
Dim I ' Looping var
'Uppercase all characters for consistency
strInput = UCase(strNumber)
'To be able to handle some pretty bad formatting we strip out
'all characters except for digits 0 to 9
For I = 1 To Len(strInput)
strCurrentChar = Mid(strInput, I, 1)
' Numbers (0 to 9)
If Asc("0") <= Asc(strCurrentChar) And Asc(strCurrentChar) <= Asc("9") Then
strTemp = strTemp & strCurrentChar
End If
Next 'I
'Swap strTemp back to strInput for next set of validation
'I also clear strTemp just for good measure!
strInput = strTemp
strTemp = ""
'Error catch to make sure strInput is proper length now that
'we've finished manipulating it.
If Not Len(strInput) = 10 Then
Err.Raise 1, "FormatPhoneNumber function", _
"- The phone number you have entered must be a valid 10 digit phone number! "
End If
'If an error occurred then the rest of this won't get processed!
'Build the output string formatted to our liking!
'(xx) xxxx-xxxx
strTemp = "(" ' "("
strTemp = strTemp & Left(strInput, 2) ' Area code
strTemp = strTemp & ") " ' ") "
strTemp = strTemp & Mid(strInput, 3, 4) ' Exchange
strTemp = strTemp & "-" ' "-"
strTemp = strTemp & Right(strInput, 4) ' 4 digit part
'Set return value
FormatPhoneNumber = strTemp
End Function
if isempty(request.form("phone")) or request.form("phone") = ""then
errorArray(1) = "True"
ErrorMsg = ErrorMsg & "- A phone number is required, just in case we need to contact you quickly. "
else
errorArray(1) = "False"
end if
On Error Resume Next
If request.form("phone")<>"" then
FormatPhoneNumber(request.form("phone"))
If Err.number then
errorArray(2) = "True"
ErrorMsg = ErrorMsg & Err.description
else
errorArray(2) = "False"
end if
end if
'Email
re.Pattern = "^\w+([-+.]\w+)*@\w+" & _
"([-.]\w+)*\.\w+([-.]\w+)*$"
results = re.Test(email)
if results then
errorArray(3) = "False"
else
errorArray(3) = "True"
ErrorMsg = ErrorMsg & "- Please correct your email address eg. yourname@domain.com.au "
end if
'Query Description
if request.form("query") = "Please select one..." then
errorArray(4) = "True"
ErrorMsg = ErrorMsg & "- Please make a query selection. "
else
errorArray(4) = "False"
end if
'Comments
if isempty(request.form("details")) or request.form("details") = "" then
errorArray(5) = "True"
ErrorMsg = ErrorMsg & "- No details have been entered, which we will need to assist you. Please try again."
else
errorArray(5) = "False"
end if
end if
'All necessary fields are correct
if request.form("isSubmitted") = "yes" and ErrorMsg = "" then
ErrorMsg = "Thank you. The information you have provided has now been sent."
'Email Message
' EMAIL MESSAGE COMPILATION
EmailMessage = "Dear McGovern Agencies,"&chr(13)&chr(13)
EmailMessage = EmailMessage & "I would like some "&query&" information as provided in the details below."&chr(13)&chr(13)
EmailMessage = EmailMessage & "DETAILS"&chr(13)
EmailMessage = EmailMessage & "========"&chr(13)
EmailMessage = EmailMessage & details&chr(13)&chr(13)
EmailMessage = EmailMessage & "Thank you and best regards,"&chr(13)&chr(13)
EmailMessage = EmailMessage &name1&chr(13)&"Tel: "&FormatPhoneNumber(phone)&chr(13)&"Email: "&email
' MAIL SUBROUTINE
' Mail variables
Set cdoConfig = CreateObject("CDO.Configuration")
With cdoConfig.Fields
.Item(cdoSendUsingMethod) = cdoSendUsingPort
.Item(cdoSMTPServer) = "mail.mcgovernagencies.com.au" 'enter Server Details
.Update
End With
ToEmail = "admin@mcgovernagencies.com.au" 'company email address
txtSubject = "McGovern Agencies - Contact Us" 'email subject heading
Set cdoMessage = CreateObject("CDO.Message")
With cdoMessage
Set .Configuration = cdoConfig
.From = request("email")
.To = ToEmail
.CC = request ("email")
.Subject = txtSubject
.TextBody = EmailMessage
.Send
End With
Set cdoMessage = Nothing
Set cdoConfig = Nothing
end if
%>
McGovern Agencies Pty Ltd | Townsville | Australia - Contact Us