-
Urgent please
I wan to make a Genelarized Server Side Validations!
Actually
I'll make One asp page for validations
and include in an every form(asp) page!
But the Problem is that:
After filling the complete information in the form then action
should goes on different page how is it :
Please send me Urgent soln
user filling after all the data in the form fields
action page remains not working properly!
For eg:
form2.asp
<!-- #INCLUDE FILE="validateform.asp"-->
<html>
<head>
<title>Simple HTML Form</title>
</head>
<body>
<form method="post" action="form2.asp" id=form1 name=form1>
<input name="formScript" type="hidden" value="<%=Request.ServerVariables("SCRIPT_ NAME"%>">
<b>Please enter your Name: </b>
<input name="username" type="text" size=30 value="<%=Server.HTMLEncode( Request.Form( "username" )%>">
<input name="username_req" type="hidden" value="You must enter a User name.">
<p>
<b>Please enter your Phone Number: </b>
<input name="PhoneNumber" type="text" size=30 value="<%=Server.HTMLEncode(Request.Form( "PhoneNumber" )%>">
<input name="PhoneNumber_req" type="hidden" value="You must enter a Phone Number.">
<input name="PhoneNumber_val" type="hidden" value="number">
<p>
<b>Please enter your Date of birth: </b>
<input name="birthdate" type="text" size=10 value="<%=Server.HTMLEncode( Request.Form( "birthdate" )%>">
<input name="birthdate_req" type="hidden" value="You must enter your date of birth.">
<input name="birthdate_val" type="hidden" value="date">
<p>
<b>Please enter your Email Address: </b>
<input name="Email" type="text" size=10 value="<%=Server.HTMLEncode( Request.Form( "email" )%>">
<input name="Email_req" type="hidden" value="You must enter your email.">
<input name="Email_val" type="hidden" value="Email">
<p>
<input type="submit" value="Save">
<input type="reset" value="reset">
</form>
</body>
</html>
Validateform.asp
<%
'==================================
' INCLUDE FILE FOR FORM VALIDATION
'==================================
'''''''''' '''''''''' '''''''''' '''''''''' '''''''''' '''''
' DECLARE GLOBAL VARIABLES
'''''''''' '''''''''' '''''''''' '''''''''' '''''''''' '''''
DIM errorMSG
Dim chk
validateForm
IF errorMSG <> "" THEN errorForm
'''''''''' '''''''''' '''''''''' '''''''''' '''''
' VALIDATE FORM
'''''''''' '''''''''' '''''''''' '''''''''' '''''''''
SUB validateForm
DIM fieldAttrib,fieldName
FOR EACH element IN Request.Form
fieldAttrib=UCASE( RIGHT( element, 4))
fieldName = LEFT( element, LEN( element ) - 4)
IF fieldAttrib = "_REQ" AND Request.Form( fieldName ) = "" THEN
errorMSG = errorMSG & " - " & Request.Form( element ) & "<p>"
END IF
IF fieldAttrib = "_VAL" AND Request.Form( fieldName ) <> "" THEN
SELECT CASE UCASE( Request.Form( element ) )
CASE "NUMBER"
IF NOT isNumeric( Request.Form( fieldName ) ) THEN
errorMSG = errorMSG & " - " & fieldName & " must be a number.<p>"
END IF
CASE "DATE"
IF NOT isDATE( Request.Form( fieldName ) ) THEN
errorMSG = errorMSG & " - " & fieldName & " must be a date.<p>"
END IF
CASE "CURRENCY"
IF NOT isNumeric( Request.Form( fieldName ) ) THEN
errorMSG = errorMSG & " - " & fieldName & " must be a money amount.<p>"
END IF
CASE "EMAIL"
IF INSTR(Request.Form(fieldname),"@"= 0 or instr(Request.Form(fieldname),"."=0 then
errorMSG = errorMSG & " - " & fieldName & " must be a email address.<p>"
end if
END SELECT
END IF
NEXT
END SUB
'''''''''' '''''''''' '''''''''' '''''''''' '''''''''
' ERROR FORM
'''''''''' '''''''''' '''''''''' '''''''''' '''''''''
SUB errorFORM
%>
<html>
<head><title>Error Form</title></head>
<body>
<b>There was a problem with the information you entered:</b>
<blockquote>
<%=errorMSG %>
</body>
</html>
<%
'Response.End
END SUB
'''''''''' '''''''''' '''''''''' '''''''''' '''''''''' '''''''''&# 39;
' DUMP ALL OF THE FORM FIELDS
'''''''''' '''''''''' '''''''''' '''''''''' '''''''''' '''''''''&# 39;
SUB formFields
DIM element, fieldAttrib
FOR EACH element IN Request.Form
fieldAttrib = UCASE( RIGHT( element, 4 ) )
IF fieldAttrib <> "_REQ" AND fieldAttrib <> "_VAL" THEN
%>
<input name="<%=element%>" type="hidden" value="<%=Server.HTMLEncode( Request.Form( element ) )%>">
<%
END IF
NEXT
END SUB
%>
Ajay Verma
-
Urgent please (reply)
Check out www.aspdb.com front page o fsite and go into SuperValidator.
FK
------------
Ajay Verma at 5/3/01 6:03:48 AM
I wan to make a Genelarized Server Side Validations!
Actually
I'll make One asp page for validations
and include in an every form(asp) page!
But the Problem is that:
After filling the complete information in the form then action
should goes on different page how is it :
Please send me Urgent soln
user filling after all the data in the form fields
action page remains not working properly!
For eg:
form2.asp
<!-- #INCLUDE FILE="validateform.asp"-->
<html>
<head>
<title>Simple HTML Form</title>
</head>
<body>
<form method="post" action="form2.asp" id=form1 name=form1>
<input name="formScript" type="hidden" value="<%=Request.ServerVariables("SCRIPT_ NAME"%>">
<b>Please enter your Name: </b>
<input name="username" type="text" size=30 value="<%=Server.HTMLEncode( Request.Form( "username" )%>">
<input name="username_req" type="hidden" value="You must enter a User name.">
<p>
<b>Please enter your Phone Number: </b>
<input name="PhoneNumber" type="text" size=30 value="<%=Server.HTMLEncode(Request.Form( "PhoneNumber" )%>">
<input name="PhoneNumber_req" type="hidden" value="You must enter a Phone Number.">
<input name="PhoneNumber_val" type="hidden" value="number">
<p>
<b>Please enter your Date of birth: </b>
<input name="birthdate" type="text" size=10 value="<%=Server.HTMLEncode( Request.Form( "birthdate" )%>">
<input name="birthdate_req" type="hidden" value="You must enter your date of birth.">
<input name="birthdate_val" type="hidden" value="date">
<p>
<b>Please enter your Email Address: </b>
<input name="Email" type="text" size=10 value="<%=Server.HTMLEncode( Request.Form( "email" )%>">
<input name="Email_req" type="hidden" value="You must enter your email.">
<input name="Email_val" type="hidden" value="Email">
<p>
<input type="submit" value="Save">
<input type="reset" value="reset">
</form>
</body>
</html>
Validateform.asp
<%
'==================================
' INCLUDE FILE FOR FORM VALIDATION
'==================================
'''''''''' '''''''''' '''''''''' '''''''''' '''''''''' '''''
' DECLARE GLOBAL VARIABLES
'''''''''' '''''''''' '''''''''' '''''''''' '''''''''' '''''
DIM errorMSG
Dim chk
validateForm
IF errorMSG <> "" THEN errorForm
'''''''''' '''''''''' '''''''''' '''''''''' '''''
' VALIDATE FORM
'''''''''' '''''''''' '''''''''' '''''''''' '''''''''
SUB validateForm
DIM fieldAttrib,fieldName
FOR EACH element IN Request.Form
fieldAttrib=UCASE( RIGHT( element, 4))
fieldName = LEFT( element, LEN( element ) - 4)
IF fieldAttrib = "_REQ" AND Request.Form( fieldName ) = "" THEN
errorMSG = errorMSG & " - " & Request.Form( element ) & "<p>"
END IF
IF fieldAttrib = "_VAL" AND Request.Form( fieldName ) <> "" THEN
SELECT CASE UCASE( Request.Form( element ) )
CASE "NUMBER"
IF NOT isNumeric( Request.Form( fieldName ) ) THEN
errorMSG = errorMSG & " - " & fieldName & " must be a number.<p>"
END IF
CASE "DATE"
IF NOT isDATE( Request.Form( fieldName ) ) THEN
errorMSG = errorMSG & " - " & fieldName & " must be a date.<p>"
END IF
CASE "CURRENCY"
IF NOT isNumeric( Request.Form( fieldName ) ) THEN
errorMSG = errorMSG & " - " & fieldName & " must be a money amount.<p>"
END IF
CASE "EMAIL"
IF INSTR(Request.Form(fieldname),"@"= 0 or instr(Request.Form(fieldname),"."=0 then
errorMSG = errorMSG & " - " & fieldName & " must be a email address.<p>"
end if
END SELECT
END IF
NEXT
END SUB
'''''''''' '''''''''' '''''''''' '''''''''' '''''''''
' ERROR FORM
'''''''''' '''''''''' '''''''''' '''''''''' '''''''''
SUB errorFORM
%>
<html>
<head><title>Error Form</title></head>
<body>
<b>There was a problem with the information you entered:</b>
<blockquote>
<%=errorMSG %>
</body>
</html>
<%
'Response.End
END SUB
'''''''''' '''''''''' '''''''''' '''''''''' '''''''''' '''''''''&# 39;
' DUMP ALL OF THE FORM FIELDS
'''''''''' '''''''''' '''''''''' '''''''''' '''''''''' '''''''''&# 39;
SUB formFields
DIM element, fieldAttrib
FOR EACH element IN Request.Form
fieldAttrib = UCASE( RIGHT( element, 4 ) )
IF fieldAttrib <> "_REQ" AND fieldAttrib <> "_VAL" THEN
%>
<input name="<%=element%>" type="hidden" value="<%=Server.HTMLEncode( Request.Form( element ) )%>">
<%
END IF
NEXT
END SUB
%>
Ajay Verma
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|