< web  portfolio >

Brenda C. Mondragon

< Main Page >


ASP :: Server-Side Form Validation


Example of server-side form validation (for empty fields only) in an ASP page, using VBScript arrays. A friendly, explanatory error message is returned if any required form fields were not filled out.



<%
' REQUIRED FIELDS
InfoValues = Array( FULLNAME, Email, Phone, _
                    Explanation, Know_Staff, Timeliness, Accuracy, Work_Completed, Time_Completed, _
                    Service_Prob, Contact_From, Assist_Action, _
                    AM_Contact, AM_Knowledge, AM_Courtesy, AM_Authority, AM_Satisfaction, _
                    AM_Overall, Maintenance, Projects, _
                    Use_Again, Will_Recommend )

InfoValuesText = Array( "Name", "Email", "Phone", _
                        "1. Explanation of service procedures", "1. Knowledgeable staff", "1. Timeliness of response to your call", _
                        "1. Accuracy in quotes", "1. Work completed by our employees", "1. Time it took to complete project", _
                        "2. Have you had a question or problem with service?", "3. Did you contact anyone...", "4. How many times did you contact...", _
                        "5. Ease of contacting your Account Manager", "5. Knowledge level of your Account Manager", "5. Courtesy of your Account Manager", _
                        "5. Account Manager's Authority to resolve...", "5. Overall Satisfaction with Account Manager", _
                        "6. Overall Satisfaction with your Account Manager", "6. Overall Satisfaction with results", "6. Overall Satisfaction with your projects", _
                        "Would you use this company again", "Would you recommend...")

Error = 0

InfoValuesLen = UBound(InfoValues)
  For i = 0 to InfoValuesLen
      If InfoValues(i) = "" then
          Error = 1
          missingFields = missingFields & "<LI>" & InfoValuesText(i)
      End If
  Next

  If Error = 1 then

      Response.Write "</head><body>"
      Response.Write "<div align=center>"
      Response.Write "<font size=""+2""><B><FONT COLOR=""#FF0000"">Error</FONT></B></font><p>"
      Response.Write "<b>You left a required field blank, please go back and make sure all required fields are filled out.</b></div>"
      Response.Write "<BR><BLOCKQUOTE><BLOCKQUOTE><B>MISSING:</B><UL>" & missingFields & "</UL></BLOCKQUOTE></BLOCKQUOTE>"
      Response.Write "<p align=center><a href=""javascript:history.go(-1)"">RETURN</a>"
      Response.Write "<BR CLEAR=ALL><BR CLEAR=ALL>"

  else

' UPDATE THE DATABASE
...
%>

Categories:



< Main Page >

This portfolio powered by Blosxom

All content Copyright © 1995 - 2024 Brenda C. Mondragon