View Full Version : Error messages on the same asp page?
yapjiwen
01-19-2004, 05:27 PM
How do we make it so that error messages appear in the same asp page as the form? I am not keen on having error messages displayed in a new page...Your comments will be appreciated ...thanks...
oracleguy
01-19-2004, 06:13 PM
After your validation script is done, if there are errors, redirect back to the form and pass the error codes?
jeskel
01-19-2004, 07:37 PM
Are you trying to do something like this?
dim error
dim errorNum
dim var1 'just an exemple of the different checks you can make with a vars
dim var2
dim var3
error = "<font face=""arial"" size=""2"" color=""red"">" 'should rather be done using CSS
errorNum=0
if request.form("action") = "submit" then 'implies that you have a button named 'submit' to validate your form
if Len(var1) = 0 then
error= error & "enter something."
errorNum=1
end if
if request.form("var2") <> request.form("var3") then
error= error & "<br />enter twice the same value"
errorNum=1
end if
if var1 = request.form("var2") then
error= error & "<br />please enter different values</font>"
errorNum=1
end if
if InStr("=", var1) = True or Instr("*", var1) = True or Instr("'",var1) = True or Instr("%",var1) = True or Instr("_",var1) = True then
error = error & "<br />forbidden chars"
errorNum=1
end if
'check for errors
if errorNum = 0 then
'do whatever you want with your data
end if
end if
error = error & "</font><br /><br />"
if request.form("action") <> "submit" or errorNum > 0 then
response.write (error)
' display your form with: action=" & Request.ServerVariables ("SCRIPT_NAME") & "
' and: <input type="submit" value="submit" name="action">
end if
I was in hurry... If something goes wrong let me know.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.