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
- <% Dim ID, RS, SQL, NAME, EMAIL, COMMENT, sDATE, IO, M_ID, SUBJECT, CITY, COUNTRY, ALLOW_E, AID, NEXT_ID, C_NAME, C_EMAIL, MESSAGE, _
-
blDONE, blLOGGED_IN
-
-
ID = Trim(Request.QueryString("ID"))
-
AID = Trim(Request.QueryString("AID"))
-
IF IS_VALID_ID(ID) = False OR IS_VALID_ID(AID) = False THEN Response.END
-
MODE = Request.Form("mode")
-
-
IF Trim(Session("PMMS_IN")) = "True" THEN blLOGGED_IN = True
-
-
IF MODE = "send" THEN
-
-
NAME = Request.Form("name")
-
EMAIL = Request.Form("email")
-
CONTENT = Request.Form("content")
-
SUBJECT = Request.Form("subject")
-
-
-
-
-
Call GET_DETAILS()
-
-
-
IF NAME = "" OR IsNull(NAME) THEN MESSAGE = MESSAGE & "<li />Please enter your name.<br />"
-
IF EMAIL = "" OR IsNull(EMAIL) THEN MESSAGE = MESSAGE & "<li />Please enter your email address.<br />"
-
IF CONTENT = "" OR IsNull(CONTENT) THEN MESSAGE = MESSAGE & "<li />Please enter your message.<br />"
-
-
IF MESSAGE = "" THEN
-
CONTENT = CONTENT & vbcrlf & vbclrf & _
-
-
Call SEND_EMAIL_OUT(CONTENT, SUBJECT, C_EMAIL, EMAIL, "smtp.myweb.com")
-
-
blDONE = True
-
-
'Response.Redirect "_comment_view.asp?ID=" & ID & "&AID=" & AID
-
'Response.END
-
-
END IF
-
-
-
ELSE
-
-
Call GET_DETAILS()
-
NAME = Session("PMMS_NAME")
-
EMAIL = Session("PMMS_EMAIL")
-
-
END IF
-
-
-
-
SUB GET_DETAILS()
-
SQL = "SELECT fldNAME, fldEMAIL, fldCOMMENT, fldDATE, fldIP, fldM_ID, fldCITY, fldCOUNTRY, fldALLOW FROM nm_tbl_comment WHERE ID = " & ID
-
Call OPEN_DB()
-
-
Set RS = Server.CreateObject("ADODB.Recordset")
-
RS.LockType = 1
-
RS.CursorType = 0
-
RS.Open SQL, MyConn
-
IF NOT RS.EOF THEN
-
C_NAME = trim(RS("fldNAME"))
-
C_EMAIL = trim(RS("fldEMAIL"))
-
ALLOW_E = trim(RS("fldALLOW"))
-
-
END IF
-
RS.Close
-
Set RS = Nothing
-
-
MyConn.Close
-
Set MyConn = Nothing
-
END SUB
-
-
-
%>
-
-
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
-
<html><head>
-
-
</head><body bgcolor="#ffffff">
-
-
<body style="overflow:hidden;">
-
-
<%IF blDONE = True THEN%>
-
-
<table width="100%" height="100%" align="top" cellpadding="2" cellspacing="0" border="0"><tr>
-
<div style="width:100%;height:100%;overflow:auto"' border=0>
-
<td align="left" valign="top">
-
<span class="style1">Thank you. Your email has been sent. </span></td>
-
</div>
-
-
<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>
-
</tr></table>
-
-
<%Response.END%>
-
<%END IF%>
-
-
<%IF NOT MESSAGE = "" THEN%>
-
<table width="95%" height="70" border="0" align="center" cellpadding="2" cellspacing="0">
-
<tr>
-
<td><%=MESSAGE%></td>
-
</tr></table>
-
<br />
-
<%END IF%>
-
<span class="style1"></td>
-
</tr>
-
</table>
-
</span>
-
<form action="?ID=<%=ID%>&AID=<%=AID%>" method="post">
-
<table cellpadding="2" cellspacing="0" border="0" width="95%" align="center"><tr>
-
<td colspan="2" class="style1">Send email to: <span style="color:#dd4800;"><strong><%=C_NAME%></strong></span></td>
-
</tr><tr>
-
<td>Your Name:</td>
-
<td><input style="width: 335px;" type="Text" name="name" value="" maxlength="180" class="textbox" /></td>
-
</tr><tr>
-
<td>Your Email:</td>
-
<td><input style="width: 335px;" type="Text" name="email" value="" maxlength="180" class="textbox" /></td>
-
</tr><tr>
-
-
<td>Subject:</td>
-
<td><input style="width: 335px;" type="Text" name="subject" value="<%=SUBJECT%>" maxlength="180" class="textbox" /></td>
-
</tr><tr>
-
<td colspan="2"><textarea class="textbox" rows="15" name="content" style="width: 100%;"><%=CONTENT%></textarea></td>
-
</tr><tr>
-
<td colspan="2"><br /><input type="Submit" value="Send Email" /></td>
-
</tr></table>
-
-
<input type="Hidden" name="mode" value="send" />
-
-
</form>
-
-
-
<p> </p>