Connecting Tech Pros Worldwide Forums | Help | Site Map

ASP pageemail form validation help

Member
 
Join Date: Mar 2007
Posts: 114
#1: Apr 26 '07
This is an email form on an ASP page. I want to add validation before it submits, The current validation only checks "name, email, and content" (server side) if the spaces are empty. I need to add the following so that the form is not submitted unless the following is true.

1. The "name" field must be maximum 20 characters. Not left empty. Letters only.
2. The "email" must be a valid email. Not left empty.
3. The "subject" must be maximum 50 characters.
4. The "content" must be maximum 4000 characters. Not left empty.


Would it be better if i also added client side javascript validation too? if so what do i add? Thanks in advance for any help. Below is the email form page

Expand|Select|Wrap|Line Numbers
  1. <% Dim ID, RS, SQL, NAME, EMAIL, COMMENT, sDATE, IO, M_ID, SUBJECT, CITY, COUNTRY, ALLOW_E, AID, NEXT_ID, C_NAME, C_EMAIL, MESSAGE, _
  2.        blDONE, blLOGGED_IN
  3.  
  4.     ID = Trim(Request.QueryString("ID"))
  5.     AID = Trim(Request.QueryString("AID"))
  6.     IF IS_VALID_ID(ID) = False OR IS_VALID_ID(AID) = False THEN Response.END
  7.     MODE = Request.Form("mode")
  8.  
  9.     IF Trim(Session("PMMS_IN")) = "True" THEN blLOGGED_IN = True    
  10.  
  11.     IF MODE = "send" THEN
  12.  
  13.         NAME = Request.Form("name")
  14.         EMAIL = Request.Form("email")
  15.         CONTENT = Request.Form("content")
  16.         SUBJECT = Request.Form("subject")
  17.  
  18.  
  19.  
  20.  
  21.         Call GET_DETAILS()        
  22.  
  23.  
  24.         IF NAME = "" OR IsNull(NAME) THEN MESSAGE = MESSAGE & "<li />Please enter your name.<br />"
  25.         IF EMAIL = "" OR IsNull(EMAIL) THEN MESSAGE = MESSAGE & "<li />Please enter your email address.<br />"
  26.         IF CONTENT = "" OR IsNull(CONTENT) THEN MESSAGE = MESSAGE & "<li />Please enter your message.<br />"
  27.  
  28.         IF MESSAGE = "" THEN
  29.             CONTENT = CONTENT &  vbcrlf & vbclrf & _
  30.  
  31.             Call SEND_EMAIL_OUT(CONTENT, SUBJECT, C_EMAIL, EMAIL, "smtp.myweb.com")
  32.  
  33.             blDONE = True
  34.  
  35.             'Response.Redirect "_comment_view.asp?ID=" & ID & "&AID=" & AID
  36.             'Response.END 
  37.  
  38.         END IF
  39.  
  40.  
  41.     ELSE
  42.  
  43.         Call GET_DETAILS()
  44.         NAME  = Session("PMMS_NAME")
  45.         EMAIL = Session("PMMS_EMAIL")
  46.  
  47.     END IF
  48.  
  49.  
  50.  
  51.     SUB GET_DETAILS()
  52.         SQL = "SELECT fldNAME, fldEMAIL, fldCOMMENT, fldDATE, fldIP, fldM_ID, fldCITY, fldCOUNTRY, fldALLOW FROM nm_tbl_comment WHERE ID = " & ID
  53.         Call OPEN_DB()
  54.  
  55.         Set RS = Server.CreateObject("ADODB.Recordset")
  56.         RS.LockType   = 1
  57.         RS.CursorType = 0
  58.         RS.Open SQL, MyConn    
  59.              IF NOT RS.EOF THEN
  60.                  C_NAME = trim(RS("fldNAME"))
  61.                 C_EMAIL = trim(RS("fldEMAIL"))                
  62.                 ALLOW_E = trim(RS("fldALLOW"))
  63.  
  64.              END IF
  65.         RS.Close 
  66.         Set RS = Nothing
  67.  
  68.         MyConn.Close
  69.         Set MyConn = Nothing        
  70.     END SUB
  71.  
  72.  
  73. %>
  74.  
  75. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  76. <html><head>
  77.  
  78.     </head><body bgcolor="#ffffff">
  79.  
  80. <body style="overflow:hidden;"> 
  81.  
  82.       <%IF blDONE = True THEN%>
  83.  
  84.     <table width="100%" height="100%" align="top" cellpadding="2" cellspacing="0" border="0"><tr>
  85.      <div style="width:100%;height:100%;overflow:auto"' border=0>
  86.             <td align="left" valign="top">    
  87.                 <span class="style1">Thank you. Your email has been sent. </span></td>
  88.      </div>          
  89.  
  90.                          <td align="right" valign="bottom"><a href="javascript:window.close();" class="style1"><img src="comment_imgs/e_close.gif" width="47" height="12" alt="" border="0" /></a></td>
  91. </tr></table>
  92.  
  93.     <%Response.END%>
  94.     <%END IF%>
  95.  
  96.     <%IF NOT MESSAGE = "" THEN%>
  97.         <table width="95%" height="70" border="0" align="center" cellpadding="2" cellspacing="0">
  98.           <tr>
  99.             <td><%=MESSAGE%></td>
  100. </tr></table>
  101.         <br />        
  102.     <%END IF%>        
  103.     <span class="style1"></td>
  104.             </tr>
  105.             </table>
  106.     </span>
  107. <form action="?ID=<%=ID%>&AID=<%=AID%>" method="post">    
  108.         <table cellpadding="2" cellspacing="0" border="0" width="95%" align="center"><tr>
  109.             <td colspan="2" class="style1">Send email to: <span style="color:#dd4800;"><strong><%=C_NAME%></strong></span></td>
  110.         </tr><tr>
  111.             <td>Your Name:</td>
  112.             <td><input style="width: 335px;" type="Text" name="name" value="" maxlength="180" class="textbox" /></td>
  113.         </tr><tr>
  114.             <td>Your Email:</td>
  115.             <td><input style="width: 335px;" type="Text" name="email" value="" maxlength="180" class="textbox" /></td>
  116.         </tr><tr>
  117.  
  118.             <td>Subject:</td>
  119.             <td><input style="width: 335px;" type="Text" name="subject" value="<%=SUBJECT%>" maxlength="180" class="textbox" /></td>
  120.         </tr><tr>
  121.             <td colspan="2"><textarea class="textbox" rows="15" name="content" style="width: 100%;"><%=CONTENT%></textarea></td>
  122.         </tr><tr>
  123.             <td colspan="2"><br /><input type="Submit" value="Send Email" /></td>
  124.         </tr></table>
  125.  
  126. <input type="Hidden" name="mode" value="send" />
  127.     &nbsp; 
  128. </form>
  129.  
  130.  
  131. <p>&nbsp;</p>

Reply