%
Function ValidateField(sFieldValue, sFieldType)
Dim bFieldIsOkay
' defaut it to true
bFieldIsOkay = True
' go to the field name to validate the entry
' This validator checks for three typs of data
' They are defined by the first 2 characters of their name
' rt = Required Text
' rs = Required State
' re = Requitred Email
' rn = Required Number
Select Case LCase(Left(sFieldType,2))
Case "rt"
If Len(sFieldValue) = 0 Then bFieldIsOkay = False
Case "rs"
If Len(sFieldValue) <> 2 Then bFieldIsOkay = False
Case "re"
If Len(sFieldValue) < 5 Then
bFieldIsOkay = False
Else
If Instr(1, sFieldValue, " ") <> 0 Then
bFieldIsOkay = False
Else
If InStr(1, sFieldValue, "@") < 2 Then
bFieldIsOkay = False
Else
If InStrRev(sFieldValue, ".") < InStr(1, sFieldValue, "@") + 2 Then
bFieldIsOkay = False
End If
End If
End If
End If
' Case "rn"
' If Not IsNumeric(sFieldValue) Then
' bFieldIsOkay = False
' End If
Case Else
End Select
ValidateField = bFieldIsOkay
End Function
'This second function will get variables from forms and/or querystrings and/or cookies,
'and write them in a form as hidden fields... This is very useful when dealing with
'multiple page forms.
'The function must be called prior to the tag, so it can include the hidden fields
'This saves the tedious task of: , etc
'This saves a lot of work when passing many, many variables.
'Usage:- Call IncludeHidden(StrType, IGNORELIST)
' Where 'StrType' is a string value of either, "form", "querystring", "cookies",
' or "all"
' and 'IGNORELIST' is a comma seperated string of field names to ignore. (Case INsensitive)
'
'EXAMPLE:- To include all values submitted to the page via
'a form, within the second form as form fields...
'
'
' If you wanted to exclude a field called 'whatever' (Perhaps the page
' receives its own data back at some stage)
' Then you could use:- <$ Call IncludeHidden("Form", "whatever") $>
' and the hidden form field named 'whatever' WONT be included
'---------------------------------------------------------------------------------------------
Function IncludeHidden(StrType, IGNORELIST)
If lcase(StrType) = "form" or lcase(StrType) = "all" then
For each Field in Request.Form
'If NOT Onlist(Field, IGNORELIST) Then
TheString="" & VbCrLf
Response.Write TheString
'End If
Next
End If
END Function
' Helper functios to save me from typing out each field.
Function ShowFormField(strQuestion, strField)
If dictFields(LCase(strField)) Then %>
<%Else%>
<% End If %>
<%= strQuestion %>:
<%
End Function
Function ShowFormYN(strQuestion, strField)
If dictFields(LCase(strField)) Then %>
<%Else%>
<% End If %>
<%= strQuestion %>:
<% End Function
Function ShowFormLength(strQuestion, strField, strLong)
If dictFields(LCase(strField)) Then %>
<%Else%>
<% End If %>
<%= strQuestion %>:
<% End Function
Function ShowFormState(strQuestion, strField)
If dictFields(LCase(strField)) Then %>
<%Else%>
<% End If %>
<%= strQuestion %>:
<% End Function %>
i-lead.com by International Leadership Associates
<%' Begin Runtime Code
' ++++++++++++++++++++ VALIDATION CODE ++++++++++++++++++++++++
' I want to maintain a list of failures so my code's not going to be
' quite as nice and neat, but I'm going to be pulling a different trick
' to save me some typing! Check out the For Each Loop! What do you want?
' I already said I was lazy!
Dim Field 'looping variable
Dim dictFields 'dictionary for failed fields
Set dictFields = Server.CreateObject("Scripting.Dictionary")
' We never need to ask for fields by name and their names
' identify them to the validation script!
For Each Field in Request.Form
If ValidateField(Request.Form(Field), Field) = False Then
dictFields.Add LCase(Field), True
End If
Next 'Field
' Troubleshooting lines - left in for when you break it!
'Response.Write Request.Form.Count
'Response.Write dictFields.Count
' Check to be sure fields were entered (Request.Form.Count <> 0)
' and correctly (dictFields.Count = 0)
' If so we process the form, o/w we show the form with checks showing
' fields to be fixed.
'
' If the Form has data AND there are no errors...
If Request.Form.Count <> 0 And dictFields.Count = 0 Then %>
<%' ++++++++++++++++++++++ Success Code +++++++++++++++++++
' ++++++++++++++++++++++++ Mail Results +++++++++++++++++++
Dim myCDONTSMail 'object
Dim strFrom 'from
Dim strTo 'to
Dim strSubject 'subject
Dim strBody 'Contents of the mail message
strFrom="ila@i-lead.com"
strTo="info@i-lead.com"
strSubject = request.form("Subject")
' ++++++++++++++++++++++++ OLD MAIL FORMAT - Replaced 10/9/2005 +++++++++++++++++++
strBody="
" & strSubject & "
"
dim ix, formElementName, formElementValue, fldName
For ix = 1 to Request.Form.Count
formElementName = Request.Form.Key(ix)
formElementValue = Request.Form.Item(ix)
If formElementName <> "Subject" Then
' and throw away prefix to get actual field name
fldName = Mid(formElementName,4)
' but change periods to spaces for readability
fldName = Replace(fldName, "."," ")
' then tack on the name of the field and the answer
strBody = strBody & "" & (fldName & ": " & formElementValue & " " & vbCrLf)
End If
Next
strBody= strBody & " Day Stamp: " & formatdatetime(now(),1) & " " & vbCrLf
' ++++++++++++++++++++++++ NEW MAIL FORMAT - 10/9/2005 +++++++++++++++++++
Set myCDONTSMail = CreateObject("CDONTS.NewMail")
myCDONTSMail.BodyFormat=0
myCDONTSMail.MailFormat=0
myCDONTSMail.From= strFrom
myCDONTSMail.To= strTo
myCDONTSMail.CC= "info@eclecticstudios.com"
myCDONTSMail.Subject= strSubject
myCDONTSMail.Body= strBody
myCDONTSMail.Send ()
If Err <> 0 Then
Response.Write "Error encountered: " & Err.Description
Else
' Commented out by DJ, 2/19/2007
' Response.Write "Thank you for submitting your information!"
End If
Set myCDONTSMail = Nothing
%>
ILA Newsletter and Distribution List Signup Signup
Thank you!
Your information has been sent.
<%Else ' If Validation Fails, or if it is the first time through... %>
<% ' ++++++++++++++++++++ Agreement Form Code ++++++++++++++++++ %>
ILA Newsletter and Distribution List Signup Signup
<% ' Two possible reasons for us to be here
' 1. It's their first visit to the page - show the form with no check marks.
' 2. They've entered data and validation failed - show why in form below!
' If they entered some data, and we're still here, then
' they must have made a mistake. Tell them so:
If Request.Form.Count <> 0 Then
%>
I'm sorry but your form wasn't
filled out correctly. Please correct the indicated fields.
<% End If %>