Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

validation errors not displaying

Status
Not open for further replies.

colinbell

Technical User
Jul 15, 2004
50
0
0
GB
Hi

I have the code below, which has worked ok up until now. The validation is now not being called - although the rcord still only inserts into the database if all validation is met. What used to happen is if validation wasn't met the page would display, in red, any errors. This is the bit that is now not working. It just always goes back to main.asp?page=539

any help appreciated
richard


<%
Response.Buffer = False

Set objCon = Server.CreateObject("ADODB.Connection")
Set objCon1 = Server.CreateObject("ADODB.Connection")
Set objRS = Server.CreateObject("ADODB.Recordset")
Set objRS1 = Server.CreateObject("ADODB.Recordset")

objCon.CursorLocation = 3
objCon.ConnectionString = "Driver=SQL Server;Server=*****;Database=Key;User ID=aspgen;Password=genasp"
objCon.Open

objCon1.CursorLocation = 3
objCon1.ConnectionString = "Driver=SQL Server;Server=*****;Database=cms_membership;User ID=aspgen;Password=genasp"
objCon1.Open

If Request.Form.Count > 0 Then
OrganisationName = Request.Form("Organisation_Name")
OrganisationType = Request.Form("Organisation_Type")
PostCode = Request.Form("PostCode")
Address = Request.Form("Address1")
Password = request.form("Password")
Password1 = request.form("Password1")
EmailAddr = request.form("email_address")
Address2_1 = request.form("Address2")
Address3_1 = request.form("Address3")
Town_1 = request.form("Town")
County_1 = request.form("County")
Telephone = request.form("Tel_No")
Fax = request.form("Fax_No")
UserFName = request.form("UserFName")
UserSName = request.form("UserSName")
Pref = request.form("Pref")

If OrganisationName = "" Then
ErrorMsg1 = ErrorMsg11 & "Please enter your Organisation Name<br>"
End If
If OrganisationType = "" Then
ErrorMsg1 = ErrorMsg1 & "Please enter an Organisation type<br>"
End If
If Address = "" Then
ErrorMsg1 = ErrorMsg1 & "Please enter an Address<br>"
End If

Dim valid_str
Dim oRegExp
Set oRegExp = New RegExp
oRegExp.IgnoreCase = False
oRegExp.pattern = valid_str
Dim matches, match
Set matches = oRegExp.Execute(Password)
For Each match in matches
If Password = "" Then
ErrorMsg1 = ErrorMsg1 & "Please enter a Password<br>"
else
If len(Password) < 8 Or len(Password) > 15 Then
ErrorMsg1 = ErrorMsg1 & "Password length must be between 8-15 characters<br>"
Else
oRegExp.pattern = "([^a-z0-9])"
If oRegExp.Test(Password) Then
ErrorMsg1 = ErrorMsg1 & "Password contains invalid characters<br>"
Else
oRegExp.pattern = "(^[^a-z]+$)|(^[^0-9]+$)"
If oRegExp.Test(Password) Then
ErrorMsg1 = ErrorMsg1 & "Password must contain at least one lowercase letter, and one number<br>"
Else
if Password1 <> Password then
ErrorMsg1 = ErrorMsg1 & "Passwords must match<br>"
end if
end if
End If
End If
end if
Next

Dim valid_str1
valid_str1 = "^[\w-_\.]+\@[\w-_]+(\.[\w-_]+)+$"
Dim oRegExp1
Set oRegExp1 = New RegExp
oRegExp1.pattern = valid_str1
If EmailAddr = "" Then
ErrorMsg1 = ErrorMsg1 & "Please enter an Email Address<br>"
else
If not oRegExp1.Test(EmailAddr) Then
ErrorMsg1 = ErrorMsg1 & "Email format must be in host@domain.com format<br>"
Else
End If
end if

Dim valid_str2
valid_str2 ="^(((([A-PR-UWYZ][0-9][0-9A-HJKS-UW]?)|([A-PR-UWYZ][A-HK-Y][0-9][0-9ABEHMNPRV-Y]?))\s{0,2}[0-9]([ABD-HJLNP-UW-Z]{2}))|(GIR\s{0,2}0AA))$"
Dim oRegExp2
Set oRegExp2 = New RegExp
oRegExp2.pattern = valid_str2
If PostCode = "" Then
ErrorMsg1 = ErrorMsg1 & "Please enter a PostCode<br>"
else
If not oRegExp2.Test(PostCode) Then
ErrorMsg1 = ErrorMsg1 & "Postcode must be in UK format<br>"
Else
End If
End if

If ErrorMsg1 = "" Then
SQLString = "INSERT INTO tblUserData("

For each Field in Request.Form
SQLString = SQLString & Field & ", "
Next

SQLString = Left(SQLString, (Len(SQLString) -2))

SQLString = SQLString + ") VALUES ("


Function cleansql(strValue)
cleansql = replace(strValue,"'","`")
End Function

For each Field in Request.Form
TheString="<input type=""HIDDEN"" name=""" & Field & """ value="""
StrValue = Request.Form(Field)
StrValue = replace(strValue, "'", "`")
TheString=TheString + cstr(StrValue) & """>" & VbCrLf
Response.Write TheString
SQLString = SQLString + "'" & replace(Request(Field),"'","`") & "', "
Next

SQLString = Left(SQLString, (Len(SQLString) -2))
SQLString = SQLString + ");"
objCon.Execute(SQLString)


<!--#include file="SendEmailFunctionCDONTS.asp"-->
SendMail "*.*****@******.***.uk", "*.******@******.***.uk", "testing", "testing"

SQLstmt = "INSERT INTO ********(MB_MEMBER,MB_PASSWORD,MB_GROUP,MB_FIRSTNAME,MB_LASTNAME,MB_ADDR1,MB_ADDR2,MB_ADDR3,MB_TOWN,MB_COUNTY,MB_POSTAL,MB_TELNO,MB_FAXNO,MB_EMAIL, MB_EXTRA, MB_KEY)"
SQLstmt = SQLstmt & " VALUES ('" & cleansql(OrganisationName) & "',"
SQLstmt = SQLstmt & "'" & cleansql(Password) & "',"
SQLstmt = SQLstmt & "'" & 10 & "',"
SQLstmt = SQLstmt & "'" & cleansql(UserFName) & "',"
SQLstmt = SQLstmt & "'" & cleansql(UserSName) & "',"
SQLstmt = SQLstmt & "'" & cleansql(Address) & "',"
SQLstmt = SQLstmt & "'" & cleansql(Address2_1) & "',"
SQLstmt = SQLstmt & "'" & cleansql(Address3_1) & "',"
SQLstmt = SQLstmt & "'" & cleansql(Town_1) & "',"
SQLstmt = SQLstmt & "'" & cleansql(County_1) & "',"
SQLstmt = SQLstmt & "'" & cleansql(PostCode) & "',"
SQLstmt = SQLstmt & "'" & cleansql(Telephone) & "',"
SQLstmt = SQLstmt & "'" & cleansql(Fax) & "',"
SQLstmt = SQLstmt & "'" & cleansql(EmailAddr) & "',"
SQLstmt = SQLstmt & "'" & cleansql(OrganisationType) & "',"
SQLstmt = SQLstmt & "001"
SQLstmt = SQLstmt & ")"

objCon1.Execute(SQLstmt)
End If
End If

%>

<%

Function KeyInputDisplay(Params, DBConn, PageID, ParentID, TopID)

Dim b, h

If ErrorMsg1 <> "" Then
b = "<BR><font color=""#FF0000"">" & ErrorMsg1 & "</font>"
else
OrganisationName = ""
OrganisationType = ""
PostCode = ""
Address = ""
Password = ""
Password1 = ""
EmailAddr = ""
Address2_1 = ""
Address3_1 = ""
Town_1 = ""
County_1 = ""
Telephone = ""
Fax = ""
UserFName = ""
UserSName = ""
Pref = ""
end if

b = b & "</p>"
b = b & "<SPAN CLASS = ""plaintext"">"
b = b & "<FORM action=""main.asp?page=539"" METHOD=""POST"" name=""formRegistration"">"
b = b & "<table width=""100%"" summary=""This table holds fields for you to complete to submit a registration request for Key magazine"">"
b = b & "<tr><td><label for=""Organisation_Name"">Organisation Name</label></td><td width=""50%""><input type=""text"" name=""Organisation_Name"" size=""20"" value=""" & OrganisationName & """></td></tr>"
b = b & "<TR><TD><label for=""Organisation_Type"">Organisation Type</label></TD><TD><select size=""1"" name=""Organisation_Type"">"
b = b & "<option value="""">Please Select......</option>"
b = b & "<option value=""Voluntary"""
if OrganisationType = "Voluntary" then
b = b & "selected >Voluntary</option>"
else
b = b & ">Voluntary</option>"
end if
b = b & "<option value=""Community Sector"""
if OrganisationType = "Community Sector" then
b = b & "selected >Community Sector</option>"
else
b = b & ">Community Sector</option>"
end if
b = b & "<option value=""Local Authority"""
if OrganisationType = "Local Authority" then
b = b & "selected >Local Authority</option>"
else
b = b & ">Local Authority</option>"
end if
b = b & "<option value=""Business User"""
if OrganisationType = "Business User" then
b = b & "selected >Business User</option>"
else
b = b & ">Business User</option>"
end if
b = b & "<option value=""Government Agency"""
if OrganisationType = "Government Agency" then
b = b & "selected >Government Agency</option>"
else
b = b & ">Government Agency</option>"
end if
b = b & "<option value=""School"""
if OrganisationType = "School" then
b = b & "selected >School</option>"
else
b = b & ">School</option>"
end if
b = b & "<option value=""Further/Higher Education"""
if OrganisationType = "Further/Higher Education" then
b = b & "selected >Further/Higher Education</option>"
else
b = b & ">Further/Higher Education</option>"
end if
b = b & "<option value=""Other"""
if OrganisationType = "Other" then
b = b & "selected >Other</option>"
else
b = b & ">Other</option>"
end if
b = b & "</option></select></td></tr></FONT><BR>"
b = b & "<TR><TD><label for=""UserFName"">First Name</label></td><td><INPUT TYPE=""TEXT"" NAME=""UserFName"" SIZE=20 iMaxLength=50 value=""" & UserFName & """><SUP> </SUP><BR>"
b = b & "<TR><TD><label for=""UserSName"">Surname</label></td><td><INPUT TYPE=""TEXT"" NAME=""UserSName"" SIZE=20 iMaxLength=50 value=""" & UserSName & """><SUP> </SUP><BR>"
b = b & "<TR><TD><label for=""PostCode"">PostCode</label></TD><TD><INPUT TYPE=""TEXT"" NAME=""PostCode"" SIZE=20 iMaxLength=50 value=""" & PostCode & """><SCRIPT LANGUAGE=Javascript>postcode_anywhere_address();</SCRIPT></td></tr><BR>"
b = b & "<TR><TD><label for=""Address1"">Address</label></td><td><INPUT TYPE=""TEXT"" NAME=""Address1"" SIZE=20 iMaxLength=50 value=""" & Address & """><SUP> </SUP><BR>"
b = b & "<tr><td><label for=""Address2""></label></td><td><INPUT TYPE=""TEXT"" NAME=""Address2"" SIZE=20 iMaxLength=50 value=""" & Address2_1 & """><SUP> </SUP><BR></tr></td>"
b = b & "<tr><td><label for=""Address3""></label></td><td><INPUT TYPE=""TEXT"" NAME=""Address3"" SIZE=20 iMaxLength=50 value=""" & Address3_1 & """><SUP> </SUP><BR></tr></td>"
b = b & "<tr><td><label for=""Town"">Town</label></td><td><INPUT TYPE=""TEXT"" NAME=""Town"" SIZE=20 iMaxLength=50 value=""" & Town_1 & """><SUP> </SUP><BR>"
b = b & "<tr><td><label for=""County"">County</label></td><td><INPUT TYPE=""TEXT"" NAME=""County"" SIZE=20 iMaxLength=50 value=""" & County_1 & """><SUP> </SUP><BR>"
b = b & "<tr><td><label for=""Pref"">Preference</label></td><td>"
b = b & "<select size=""1"" name=""Pref"">"
b = b & "<option selected value="""">Please Select......</option>"
b = b & "<option value=""Electronic"""
if Pref = "Electronic" then
b = b & "selected >Electronic</option>"
else
b = b & ">Electronic</option>"
end if
b = b & "<option value=""Postal"""
if Pref = "Postal" then
b = b & "selected >Postal</option>"
else
b = b & ">Postal</option>"
end if
b = b & "</option></select></td><td><BR>"
b = b & "<tr><td><label for=""Tel_No"">Telephone</label></td><td><INPUT TYPE=""TEXT"" NAME=""Tel_No"" SIZE=20 iMaxLength=50 value=""" & Telephone & """><SUP> </SUP><BR>"
b = b & "<tr><td><label for=""Fax_No"">Fax</label></td><td><INPUT TYPE=""TEXT"" NAME=""Fax_No"" SIZE=20 iMaxLength=50 value=""" & Fax & """><SUP> </SUP><BR>"
b = b & "<tr><td><label for=""email_address"">Email Address</label></td><td><INPUT TYPE=""TEXT"" NAME=""email_address"" SIZE=20 iMaxLength=50 value=""" & EmailAddr & """ ><SUP> </SUP><BR>"
b = b & "<tr><td><label for=""Password"">Password</label></td><td><INPUT TYPE=""PASSWORD"" NAME=""Password"" SIZE=20 iMaxLength=20 value=""" & Password & """><SUP> </SUP><BR>"
b = b & "<tr><td><label for=""Password1"">Retype Password</label></td><td><INPUT TYPE=""PASSWORD"" NAME=""Password1"" SIZE=20 iMaxLength=20 value=""" & Password1 & """><SUP> </SUP><BR>"
b = b & "<tr><td></td><td><INPUT TYPE=""HIDDEN"" NAME=""submitted"" SIZE=20 iMaxLength=20 value=""" & formatdatetime(now(),vblongdate) & """><SUP> </SUP><BR>"
b = b & "</td></tr>"
b = b & "<table summary=""Submit and Reset buttons"">"
b = b & "<BR>"
b = b & "<INPUT TYPE=""submit"" value=""Proceed""><INPUT TYPE=""reset"" value=""Clear Form"">"
b = b & "</FORM>"
b = b & "</table>"
b = b & "</SPAN>"

objBODY = b
objHEAD = "<SCRIPT SRC="" LANGUAGE=Javascript></SCRIPT>"
objONLOAD = ""
objONRESIZE = ""
objONUNLOAD = ""

KeyInputDisplay = True

End Function

Function KeyInputIsSupported(Params, DBConn, PageID, ParentID, TopID, PublishType)
' We may need to do some database lookups to work out if the page can be
' published in a particular way
select case UCase(PublishType)
case "HTM"
KeyInputIsSupported = True
case "ASP"
KeyInputIsSupported = True
case else
KeyInputIsSupported = True
end select
End Function

Function KeyInputPublish(Params, DBConn, PageID, ParentID, TopID, PublishType)
KeyInputPublish = KeyInputDisplay(Params, DBConn, PageID, ParentID, TopID)
End Function

%>
 
Man, that code is a mess.

The part that used to print your red text is the function KeyInputDisplay. It used to be called by KeyInputPublish. Neither is called in the code you posted, so even though the code to write the red text is there, it will never work.

I can't fathom why KeyInputPublish would be called instead of KeyInputDisplay. It apprears (maybe?) that KeyInputDisplay was something that would be called in lieu of a redirect, perhaps, or...

From your question I'm guessing that you didn't write the code. If you did, sorry if you feel insulted, but like I said, that code is a real mess.
 
i cant tell if this is the same page or not, but if this code is posting back to itself you might need to response.expires=0 and no-cache it, you may just be getting the same page view you had before the post. ( just in case there's more code that wasn't supplied )

and as genimuse mentioned you have your errormsg1 response.write inside of keyinputdisplay function that's called from keyinputpublish function but yet keyinputpublish isn't called at all in the supplied code.

[thumbsup2]DreX
aKa - Robert
if all else fails, light it on fire and do the happy dance!
 
thanks

your ok genimuse - I'm not insulted - the framework i.e the keyInputDisplay and KeyInputPublish part is a 3rd party product that I'm trying to fit my asp within - I will seperate the validation header stuff from the body when I've got more time..............the product has so many bugs in it and infact this was one of them ! its sorted now - thanks anyway
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top