<html>
<body>
<%
' ROUCHIE'S VALIDATION LOGIC...
' 1. Gather form values into ASP variables
Dim var1 ' this must be text and not blank (checked later)
Dim var2 ' this must be numeric and not blank (checked later)
Dim var3 ' this must be a date and not blank (checked later)
Dim errorText ' holds error details
var1 = Trim(Request.Form("myField1"))
var2 = Trim(Request.Form("myField2"))
var3 = Trim(Request.Form("myField3"))
errorText = "" ' clear errorText variable
' 2. Check values
IF var1 = "" THEN
errorText = errorText & "<li>Field 1 cannot be blank!</li>"
END IF
IF var2 = "" OR NOT IsNumeric(var2) THEN
errorText = errorText & "<li>Field 2 cannot be blank and must be a number!</li>"
END IF
IF var3 = "" OR NOT IsDate(var3) THEN
errorText = errorText & "<li>Field 3 cannot be blank and must be a valid date!</li>"
END IF
' 3. SQL Injection Protection - replace any single quotes with 2 single quotes (for text values)
var1 = Replace(var1, "'", "''")
' 4. If errors have occurred provide a message, or otherwise save to database
IF errorText <> "" THEN
%>
<p>Errors where found in the form submission. Please check the following errors and retry:</p>
<ul>
<%=errorText%>
</ul>
<%
ELSE ' no errors - save to database
' database code
' goes here
' to save form to database
%>
<p>The data was saved successfully.</p>
<%
END IF
%>
</body>
</html>