|
|
 |
Re: FN-FORUM vbscript
date posted 23rd January 2003 18:22
right, you're not passing any variables to the function which is part of why
it isnt working.
remember a function is *self-contained* it cannot access the variables
outside the function - you have to pass them variables to process.
so the function should be more like:
function valid_form(strName, strAddress, strAddress1.....,strTel)
Response.write("bbb")
Dim Name_Error_msg
Dim Address_error_msg
Dim Address1_error_msg
Dim Town_error_msg
Dim County_error_msg
Dim Postcode_error_msg
Dim HomeTel_error_msg
Dim Email_error_msg
Dim Comment_error_msg
Dim Error_msgs
Error_msgs = 0
if Not validnamecontents(strName) Then
Name_Error_msg = "Please complete a valid Name"
Error_msgs = Error_msgs + 1
End if
.
.
.
.
end function
and called like this:
if valid_form(trim(Request.Form("Name")), trim(Request.Form("Address")),
trim(Request.Form("Address1"))...trim(Request.Form("HomeTel")))
tbh, you'd be better doing it as a sub and setting a variable - a sub will
be able to read the form variables without them having to be passed to it -
and after calling the sub checking the variable.
you're also not closing all your brackets:
validnamecontents(Request.Form("Name") should be
validnamecontents(Request.Form("Name"))
also you might want to just do an inStr() on the email for checking illegal
characters as opposed to looping through the string
----- Original Message -----
From: "PAMELA WHITTAKER" [EMAIL REMOVED]
To: [EMAIL REMOVED]
Sent: Thursday, January 23, 2003 5:38 PM
Subject: Re: FN-FORUM vbscript
It is a bit long but here it is - Thanks Pam
Function valid_form()
Response.write("bbb")
Dim Name_Error_msg
Dim Address_error_msg
Dim Address1_error_msg
Dim Town_error_msg
Dim County_error_msg
Dim Postcode_error_msg
Dim HomeTel_error_msg
Dim Email_error_msg
Dim Comment_error_msg
Dim Error_msgs
Error_msgs = 0
if Not validnamecontents(Request.Form("Name") Then
Name_Error_msg = "Please complete a valid Name"
Error_msgs = Error_msgs + 1
End if
if Not validaddresscontents(Request.Form("Address") Then
Address_error_msg = "Please complete a valid Address"
Error_msgs = Error_msgs + 1
End if
if Not validaddress2contents(Request.Form("Address1") Then
alert("a")
Address1_error_msg = "Please complete a valid Address or leave blank"
Error_msgs = Error_msgs + 1
End if
if Not validaddresscontents(Request.Form("Town") Then
Town_error_msg = "Please complete a valid Town"
Error_msgs = Error_msgs + 1
End if
if Not validaddress2contents(Requst.Form("County") Then
County_error_msg = "Please complete a valid County")
Error_msgs = Error_msgs + 1
End if
if Not validpostcodecontents(Request.Form("Postcode")
Postcode_error_msg = "Please complete a valid Postcode"
Error_msgs = Error_msgs + 1
End if
if Not validtelephonecontents(Request.Form("HomeTel")
HomeTel_error_msg = "Please complete your contact telephone number"
Error_msgs = Error_msgs + 1
End if
//CHECK EMAIL ADDRESS IF NOT BLANK (inputbox)
Dim inputbox = Request.form("Email")
if Len(inputbox)!= 0 Then
// Convert inputbox to string
Dim teststring
teststring = CStr(inputbox)
// Check for at least 7 chrs
if Len(teststring) dotpositionback Then
Email_error_msg = "The email address you have entered is not a valid
format"
Error_msgs = Error_msgs + 1
End if
End if
if Not validcommentscontents(Request.Forms("Comments")) Then
Comment_error_msg = "Please complete a valid comments/enquiries field"
Error_msgs = Error_msgs + 1
End if
if Error_msgs > 0 Then
valid_form = False
Else
valid_form = True
End if
End Function
Function validcommentscontents(inputbox)
Dim teststring
teststring = CStr(inputbox)
teststring = Trim(teststring)
if teststring = "" Then
validcommentscontents = False
Exit Function
End if
if IsNumeric(teststring) Then
validcommentscontents = False
Exit Function
End if
validcommentscontents = True
End Function
Function validnamecontents(inputbox)
Dim teststring
teststring = CStr(inputbox)
teststring = Trim(teststring)
if teststring = "" Then
validnamecontents = False
Exit Function
End if
if IsNumeric(teststring) Then
validnamecontents = False
Exit Function
End if
if Len(inputbox) < 2 Then
validnamecontents = False
Exit Function
End if
validnamecontents = True
End Function
Function checkvalidaddresscontents(inputbox)
Dim teststring
teststring = CStr(inputbox)
teststring = Trim(teststring)
if teststring = "" Then
checkvalidaddresscontents = False
Exit Function
End if
if IsNumeric(teststring) Then
checkvalidaddresscontents = False
Exit Function
End if
checkvalidaddresscontents = True
End Function
Function validaddress2contents(inputbox)
Dim teststring
teststring = CStr(inputbox)
teststring = Trim(teststrimg)
if teststring = "" Then
checkvalidaddresscontents = True
Exit Function
End if
if IsNumeric(teststring) Then
checkvalidaddresscontents = False
Exit Function
End if
checkvalidaddresscontents = True
End Function
Function validpostcodecontents(inputbox)
Dim teststring
teststring = CStr(inputbox)
teststring = Trim(teststring)
if testString = "" Then
validpostcodecontents = True
Exit Function
End if
if IsNumeric(teststring) Then
validpostcodecontents = False
Exit Function
End if
if (Len(teststring) < 2 Or Len(teststring.length) > 8) {
validpostcodecontents = False
Exit Function
}
validpostcodecontents = True
End Function
Function validtelephonecontents(inputbox)
var teststring
teststring = CStr(inputbox)
if Trim(teststring) = "" Then
validtelephonecontents = True
Exit Function
End if
Dim count = 0
While count < Len(inputbox)
Dim c = Mid(inputbox, count, 1)
if ((c Not = " ") And (c Not = "-") And Not IsNumeric(c)) Then
validtelephonecontents = False
Exit Function
}
count = count + 1
Wend
return 0
End Function
'
NTMail K12 - the Mail Server for Education
========
Freelancers and Freelance Jobs: http://www.freelancers.net
Advertise with Freelancers.net http://www.freelancers.net/advert.php
To unsubscribe please email:
[EMAIL REMOVED]
If you have difficulties unsubscribing please email:
[EMAIL REMOVED]
|
 |
|