%@ Language=VBScript %>
<% option explicit %>
User Demographic Information Form
<%
dim firstname
dim lastname
dim address1
dim address2
dim city
dim state
dim zip
dim chk16
dim getNews
dim newsletter
dim notes
dim i
dim errorMsg
errorMsg=vbnullstring
if Request.ServerVariables("REQUEST_METHOD") = "POST" then
firstname = Request.Form("firstname")
lastname = Request.Form("lastname")
address1 = Request.Form("address1")
address2 = Request.Form("address2")
city = Request.Form("city")
state = Request.Form("state")
zip = Request.Form("zip")
getNews=Request.Form("getNews") = "on"
newsletter=Request.Form("newsletter")
notes=Request.Form("notes")
firstname = trim(firstname)
lastname = trim(lastname)
address1 = trim(address1)
address2 = trim(address2)
city = trim(city)
state = trim(state)
zip = trim(zip)
if len(lastName) = 0 then
errorMsg = "You must enter your last name."
else
for i = 1 to len(lastName)
if instr(1, "abcdefghijklmnopqrstuvwxyz'", _
mid(lastName,i,1), vbTextCompare) = 0 then
errorMsg="The last name you entered is " & _
"invalid. Please re-enter your last name."
exit for
end if
next
end if
if len(errorMsg) = 0 then
if len(firstName) = 0 then
errorMsg="You must enter your first name."
else
for i = 1 to len(firstName)
if instr(1, "abcdefghijklmnopqrstuvwxyz '", _
mid(firstName,i,1), vbTextCompare) = 0 then
errorMsg="The first name you entered " _
& "is invalid. Please re-enter your " _
& "first name."
exit for
end if
next
end if
end if
if len(errorMsg) = 0 then
if len(city) = 0 then
errorMsg="You must enter the city in which you live."
else
for i = 1 to len(city)
if instr(1, "abcdefghijklmnopqrstuvwxyz '", _
mid(city,i,1), vbTextCompare) = 0 then
errorMsg="The city you entered is invalid. Please " _
& "re-enter the name of the city in which you live."
exit for
end if
next
end if
end if
if len(errorMsg) = 0 then
if len(address1) = 0 then
errorMsg="You must enter your address."
else
' can't check addresses for validity easily
end if
end if
' don't check address2 because it may not be required.
if len(errorMsg) = 0 then
if len(zip) = 0 then
errorMsg="You must enter your zip code."
elseif len(zip) < 5 then
errorMsg="The zip code you entered is invalid. Please " _
& "re-enter the zip code."
elseif len(zip) > 5 and instr(zip,"-") = 0 then
errorMsg="The zip code you entered is invalid. Please " _
& "re-enter the zip code."
elseif len(zip) > 12 then
errorMsg="The zip code you entered is invalid. Please " _
& "re-enter the zip code."
else
for i = 1 to len(zip)
if instr(1, "0123456789-",mid(zip,i,1), _
vbBinaryCompare) = 0 then
errorMsg="The zip code you entered is invalid. " _
& "Please re-enter the zip code."
exit for
end if
next
end if
end if
if len(errorMsg) = 0 then
if len(getNews) > 0 then
select case newsletter
case "Daily", "Weekly", "Monthly"
' OK
case else
errorMsg="Select how often you wish to receive our newsletter via email."
end select
end if
end if
if len(errorMsg) = 0 then
' no validation errors occurred
Response.Write "FirstName=" & firstName & "
"
Response.Write "LastName=" & lastname & "
"
Response.Write "Address1=" & address1 & "
"
Response.Write "Address2=" & address2 & "
"
Response.Write "City=" & city & "
"
Response.Write "State=" & state & "
"
Response.Write "Zip=" & zip & "
"
Response.Write "Receive Newsletter=" & getNews & "
"
Response.Write "Newsletter Schedule=" & newsletter & "
"
Response.Write "Notes=" & notes
Response.end
end if
end if
%>
This is an HTML form. It should look familiar. It contains several
text boxes and two buttons. All of the values are required.
Fill out the form and click the Submit button. To reset the form to
the initial values, click the Reset button.
Enter your information, then click Submit