473,698 Members | 2,557 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ASP pageemail form validation help

114 New Member
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>
Apr 26 '07 #1
0 1334

Sign in to post your reply or Sign up for a free account.

Similar topics

4
2643
by: bnp | last post by:
Hi All, I am quite new the JavaScript. Basically I am a C++ programmer, but now I am working on JavaScript since last 5 days. I have a problem regarding the form validation. I have created a script that validates the form fields. the validation procedure is called ONCLICK event of the submit button. Follwowing is the structure of the validation procedure.
9
4174
by: julie.siebel | last post by:
Hello all! As embarrassing as it is to admit this, I've been designing db driven websites using javascript and vbscript for about 6-7 years now, and I am *horrible* at form validation. To be honest I usually hire someone to do it for me, grab predone scripts and kind of hack out the parts that I need, or just do very minimal validation (e.g. this is numeric, this is alpha-numeric, etc.)
27
4745
by: Chris | last post by:
Hi, I have a form for uploading documents and inserting the data into a mysql db. I would like to validate the form. I have tried a couple of Javascript form validation functions, but it appears that the data goes straight to the processing page, rather than the javascript seeing if data is missing and popping up an alert. I thought it may be because much of the form is populated with data from the db (lists, etc.), but when I leave...
5
3219
by: lucyh3h | last post by:
Hi, I am trying to use XMLHttpRequest to do server side validation. I have several fields on a form and a submit button. The submit button has an event assocated with it when clicked. The javascript method will do the form validation for each field one by one. For each field, an XMLHttpRequst will be made to a PHP file and get the return, either set an error field (<span>'s innerHTML) or leave it empty. Then I'll check the error field...
0
8683
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8610
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
6528
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5862
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4372
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4623
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2339
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.