473,545 Members | 2,041 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Validating a HTML form

Does anyone know of a way to quickly validate an HTML web
form? I need to make sure that certain fields on my form
actually contain data and are not submitted blank.

I have tried using client-side Javascript validation which
flags up when a field is empty but the form is still
submitted.

Here is the ASP code I am using to submit the form to an e-
mail with CDONTS:

<%
Dim strApplicantNam e
Dim strPhoneNumber
Dim strLocation
Dim strLineManagerN ame
Dim strFirstDayHol
Dim strFirstMonthHo l
Dim strFirstYearHol
Dim strLastDayHol
Dim strLastMonthHol
Dim strLastYearHol
Dim strNoDaysOff
Dim strHalfDay
Dim strHalfDayPerio d
Dim strFurtherComme nts
Dim strConfirmEmail
Dim strTheDate
Dim strTheTime
Dim objCDO

strApplicantNam e = request.form("A pplicantName")
strPhoneNumber = request.form("P honeNumber")
strLocation = request.form("L ocation")
strLineManagerN ame = request.form
("LineManagerNa me")
strFirstDayHol = request.form("F irstDayHol")
strFirstMonthHo l = request.form("F irstMonthHol")
strFirstYearHol = request.form("F irstYearHol")
strLastDayHol = request.form("L astDayHol")
strLastMonthHol = request.form("L astMonthHol")
strLastYearHol = request.form("L astYearHol")
strNoDaysOff = request.form("N oDaysOff")
strHalfDay = request.form("H alfDay")
strHalfDayPerio d = request.form("H alfDayPeriod")
strFurtherComme nts = request.form
("FurtherCommen ts")
strConfirmEmail = request.form("C onfirmEmail")
strTheDate = Date
strTheTime = Time

Set objCDO = Server.CreateOb ject("CDONTS.Ne wMail")

objCDO.From = "we*****@abc.co m"

objCDO.To = "ho**********@a bc.com"

objCDO.Cc = strConfirmEmail

objCDO.Subject = "Driver Holiday Application"

objCDO.Body = "<html><body><h 2>Driver Holiday
Application:</h2>" _
& "<font face='Courier'> <font size='1'><b>For m
Submitted...... ...</b> " & strTheDate & " at " &
strTheTime & " <br><br>" _
& "<b>Name....... ............</b> " &
strApplicantNam e & " <br>" _
& "<b>Applica nt Location.....</b> " & strLocation & "
<br>" _
& "<b>Contact Number......... </b> " & strPhoneNumber
& " <br>" _
& "<b>Line Manager........ ...</b> " &
strLineManagerN ame & " <br>" _
& "<b>First day of Holiday...</b> " & strFirstDayHol
& " " & strFirstMonthHo l & " " & strFirstYearHol & " <br>"
_
& "<b>Last day of Holiday....</b> " & strLastDayHol
& " " & strLastMonthHol & " " & strLastYearHol & " <br>" _
& "<b>Total working days off.</b> " & strNoDaysOff
& " Day(s)" & " + " & strHalfDay & " " & "Half Day(s)" & "
(" & strHalfDayPerio d & ")" &" <br>" _
& "<b><br>Confirm ation sent to...</b> " &
strConfirmEmail & " <br>" _
& "<p><u><b>Furth er Comments:</u></b><br><br> " &
strFurtherComme nts & "</p>" _
& Comments _
& "</body></html>"

objCDO.BodyForm at = 0

objCDO.MailForm at = 0

objCDO.Send

Set objCDO = Nothing

Response.Redire ct "dri_confirm.ht m"
%>
Jul 19 '05 #1
4 2352
If *all* you want to do is ensure that a field is not blank then you could
do:

blnError = CheckRequestFor Blanks()
If blnError Then
' there is a blank
Else
' there is no blank
End If

Function CheckRequestFor Blanks( _
)

For Each Item in Request.Form()
If Trim(Request.Fo rm(Item)) = "" then
CheckRequestFor Blanks = True
Exit Function
End If
Next

CheckRequestFor Blanks = False

End Function

However, you'll probably want something more robust further along the way.
Try:
http://www.adopenstatic.com/resource...Validation.asp
for something to get you started.

Cheers
Ken
"Andrew Williams" <as*@sds.com> wrote in message
news:47******** *************** *****@phx.gbl.. .
: Does anyone know of a way to quickly validate an HTML web
: form? I need to make sure that certain fields on my form
: actually contain data and are not submitted blank.
:
: I have tried using client-side Javascript validation which
: flags up when a field is empty but the form is still
: submitted.
:
: Here is the ASP code I am using to submit the form to an e-
: mail with CDONTS:
:
: <%
: Dim strApplicantNam e
: Dim strPhoneNumber
: Dim strLocation
: Dim strLineManagerN ame
: Dim strFirstDayHol
: Dim strFirstMonthHo l
: Dim strFirstYearHol
: Dim strLastDayHol
: Dim strLastMonthHol
: Dim strLastYearHol
: Dim strNoDaysOff
: Dim strHalfDay
: Dim strHalfDayPerio d
: Dim strFurtherComme nts
: Dim strConfirmEmail
: Dim strTheDate
: Dim strTheTime
: Dim objCDO
:
: strApplicantNam e = request.form("A pplicantName")
: strPhoneNumber = request.form("P honeNumber")
: strLocation = request.form("L ocation")
: strLineManagerN ame = request.form
: ("LineManagerNa me")
: strFirstDayHol = request.form("F irstDayHol")
: strFirstMonthHo l = request.form("F irstMonthHol")
: strFirstYearHol = request.form("F irstYearHol")
: strLastDayHol = request.form("L astDayHol")
: strLastMonthHol = request.form("L astMonthHol")
: strLastYearHol = request.form("L astYearHol")
: strNoDaysOff = request.form("N oDaysOff")
: strHalfDay = request.form("H alfDay")
: strHalfDayPerio d = request.form("H alfDayPeriod")
: strFurtherComme nts = request.form
: ("FurtherCommen ts")
: strConfirmEmail = request.form("C onfirmEmail")
: strTheDate = Date
: strTheTime = Time
:
: Set objCDO = Server.CreateOb ject("CDONTS.Ne wMail")
:
: objCDO.From = "we*****@abc.co m"
:
: objCDO.To = "ho**********@a bc.com"
:
: objCDO.Cc = strConfirmEmail
:
: objCDO.Subject = "Driver Holiday Application"
:
: objCDO.Body = "<html><body><h 2>Driver Holiday
: Application:</h2>" _
: & "<font face='Courier'> <font size='1'><b>For m
: Submitted...... ...</b> " & strTheDate & " at " &
: strTheTime & " <br><br>" _
: & "<b>Name....... ............</b> " &
: strApplicantNam e & " <br>" _
: & "<b>Applica nt Location.....</b> " & strLocation & "
: <br>" _
: & "<b>Contact Number......... </b> " & strPhoneNumber
: & " <br>" _
: & "<b>Line Manager........ ...</b> " &
: strLineManagerN ame & " <br>" _
: & "<b>First day of Holiday...</b> " & strFirstDayHol
: & " " & strFirstMonthHo l & " " & strFirstYearHol & " <br>"
: _
: & "<b>Last day of Holiday....</b> " & strLastDayHol
: & " " & strLastMonthHol & " " & strLastYearHol & " <br>" _
: & "<b>Total working days off.</b> " & strNoDaysOff
: & " Day(s)" & " + " & strHalfDay & " " & "Half Day(s)" & "
: (" & strHalfDayPerio d & ")" &" <br>" _
: & "<b><br>Confirm ation sent to...</b> " &
: strConfirmEmail & " <br>" _
: & "<p><u><b>Furth er Comments:</u></b><br><br> " &
: strFurtherComme nts & "</p>" _
: & Comments _
: & "</body></html>"
:
: objCDO.BodyForm at = 0
:
: objCDO.MailForm at = 0
:
: objCDO.Send
:
: Set objCDO = Nothing
:
: Response.Redire ct "dri_confirm.ht m"
: %>
:
:
Jul 19 '05 #2

"Andrew Williams" <as*@sds.com> wrote in message
news:47******** *************** *****@phx.gbl.. .
Does anyone know of a way to quickly validate an HTML web
form? I need to make sure that certain fields on my form
actually contain data and are not submitted blank.

Here is a very simple example:

<%
If Request.ServerV ariables("REQUE ST_METHOD") = "POST" Then
sName = Request.Form("t xtName")
If Trim(sName) = "" Then
sMessage = "Please enter your name."
bDisplayError = True
End If
End If
%>

<html>
<body>
<form method="post">
<% If bDisplayError Then Response.Write sMessage %>
<input type="text" name="txtName">
<input type="submit">
</form>
</body>
</html>
Ray at work
Jul 19 '05 #3
I'll try the web site you suggested.

Thanks.
-----Original Message-----
If *all* you want to do is ensure that a field is not blank then you coulddo:

blnError = CheckRequestFor Blanks()
If blnError Then
' there is a blank
Else
' there is no blank
End If

Function CheckRequestFor Blanks( _
)

For Each Item in Request.Form()
If Trim(Request.Fo rm(Item)) = "" then
CheckRequestFor Blanks = True
Exit Function
End If
Next

CheckRequestFor Blanks = False

End Function

However, you'll probably want something more robust further along the way.Try:
http://www.adopenstatic.com/resource...Validation.asp
for something to get you started.

Cheers
Ken
"Andrew Williams" <as*@sds.com> wrote in message
news:47******* *************** ******@phx.gbl. ..
: Does anyone know of a way to quickly validate an HTML web: form? I need to make sure that certain fields on my form
: actually contain data and are not submitted blank.
:
: I have tried using client-side Javascript validation which: flags up when a field is empty but the form is still
: submitted.
:
: Here is the ASP code I am using to submit the form to an e-: mail with CDONTS:
:
: <%
: Dim strApplicantNam e
: Dim strPhoneNumber
: Dim strLocation
: Dim strLineManagerN ame
: Dim strFirstDayHol
: Dim strFirstMonthHo l
: Dim strFirstYearHol
: Dim strLastDayHol
: Dim strLastMonthHol
: Dim strLastYearHol
: Dim strNoDaysOff
: Dim strHalfDay
: Dim strHalfDayPerio d
: Dim strFurtherComme nts
: Dim strConfirmEmail
: Dim strTheDate
: Dim strTheTime
: Dim objCDO
:
: strApplicantNam e = request.form ("ApplicantName "): strPhoneNumber = request.form("P honeNumber")
: strLocation = request.form("L ocation")
: strLineManagerN ame = request.form
: ("LineManagerNa me")
: strFirstDayHol = request.form("F irstDayHol")
: strFirstMonthHo l = request.form ("FirstMonthHol "): strFirstYearHol = request.form("F irstYearHol")
: strLastDayHol = request.form("L astDayHol")
: strLastMonthHol = request.form("L astMonthHol")
: strLastYearHol = request.form("L astYearHol")
: strNoDaysOff = request.form("N oDaysOff")
: strHalfDay = request.form("H alfDay")
: strHalfDayPerio d = request.form ("HalfDayPeriod "): strFurtherComme nts = request.form
: ("FurtherCommen ts")
: strConfirmEmail = request.form("C onfirmEmail")
: strTheDate = Date
: strTheTime = Time
:
: Set objCDO = Server.CreateOb ject("CDONTS.Ne wMail")
:
: objCDO.From = "we*****@abc.co m"
:
: objCDO.To = "ho**********@a bc.com"
:
: objCDO.Cc = strConfirmEmail
:
: objCDO.Subject = "Driver Holiday Application"
:
: objCDO.Body = "<html><body><h 2>Driver Holiday
: Application:</h2>" _
: & "<font face='Courier'> <font size='1'><b>For m
: Submitted...... ...</b> " & strTheDate & " at " &
: strTheTime & " <br><br>" _
: & "<b>Name....... ............</b> " &
: strApplicantNam e & " <br>" _
: & "<b>Applica nt Location.....</b> " & strLocation & ": <br>" _
: & "<b>Contact Number......... </b> " & strPhoneNumber: & " <br>" _
: & "<b>Line Manager........ ...</b> " &
: strLineManagerN ame & " <br>" _
: & "<b>First day of Holiday...</b> " & strFirstDayHol: & " " & strFirstMonthHo l & " " & strFirstYearHol & " <br>": _
: & "<b>Last day of Holiday....</b> " & strLastDayHol
: & " " & strLastMonthHol & " " & strLastYearHol & " <br>" _: & "<b>Total working days off.</b> " & strNoDaysOff
: & " Day(s)" & " + " & strHalfDay & " " & "Half Day(s)" & ": (" & strHalfDayPerio d & ")" &" <br>" _
: & "<b><br>Confirm ation sent to...</b> " &
: strConfirmEmail & " <br>" _
: & "<p><u><b>Furth er Comments:</u></b><br><br> " &
: strFurtherComme nts & "</p>" _
: & Comments _
: & "</body></html>"
:
: objCDO.BodyForm at = 0
:
: objCDO.MailForm at = 0
:
: objCDO.Send
:
: Set objCDO = Nothing
:
: Response.Redire ct "dri_confirm.ht m"
: %>
:
:
.

Jul 19 '05 #4
client-side Javascript validation can be written to return
fales to a form submital or even an 'onchange' or
an 'onclick' event. I've found it to be th emost browser
compatiable. Try:

IN PAGE HEADER:
<script language="JavaS cript">
<!-- script start

// Ensure the mandatory fields of
// form have been completed
function validateComplet e(formObj)
{

if (emptyField(for mObj.fname))
alert("The FIRST NAME field has been left blank and is
required.");
else if (emptyField(for mObj.lname))
alert("The LAST NAME field has been left blank and is
required.");
else if (emptyField(for mObj.add1))
alert("The ADDRESS1 field has been left blank and is
required.");
else if (emptyField(for mObj.city1))
alert("The CITY field has been left blank and is
required.");
else if (emptyField(for mObj.zipcode))
alert("The ZIP CODE field has been left blank and is
required.");
else if (emptyField(for mObj.phone1))
alert("The PHONE1 field has been left blank and is
required.");
else if (!validGomail(f ormObj.emailadd ))
alert("The Invalid EMAIL ADDRESS format, please
correct.\n\n Example:\n yo*******@compa ny.com.");
else if (emptyField(for mObj.password1) )
alert("The PASSWORD field has been left blank and is
required.");
else return true;

return false;

}
// Check to see if field is empty
function emptyField(text Obj)
{
if (textObj.value. length == 0) return true;
for (var i=0; i<textObj.value .length; ++i) {
var ch = textObj.value.c harAt(i);
if (ch != ' ' && ch != '\t') return false;
}
return true;
}

// script end -->
</script>

ON FORM LINE:
<form ACTION="sign_up _continue.asp" METHOD="POST"
name="form1" id="form1" onSubmit="retur n validateComplet e
(document.form1 )">

Let me know if you need more code via email.
Christopher
-----Original Message-----
Does anyone know of a way to quickly validate an HTML web
form? I need to make sure that certain fields on my form
actually contain data and are not submitted blank.

I have tried using client-side Javascript validation whichflags up when a field is empty but the form is still
submitted.

Here is the ASP code I am using to submit the form to an e-mail with CDONTS:

<%
Dim strApplicantNam e
Dim strPhoneNumber
Dim strLocation
Dim strLineManagerN ame
Dim strFirstDayHol
Dim strFirstMonthHo l
Dim strFirstYearHol
Dim strLastDayHol
Dim strLastMonthHol
Dim strLastYearHol
Dim strNoDaysOff
Dim strHalfDay
Dim strHalfDayPerio d
Dim strFurtherComme nts
Dim strConfirmEmail
Dim strTheDate
Dim strTheTime
Dim objCDO

strApplicantNam e = request.form("A pplicantName")
strPhoneNumber = request.form("P honeNumber")
strLocation = request.form("L ocation")
strLineManagerN ame = request.form
("LineManagerN ame")
strFirstDayHol = request.form("F irstDayHol")
strFirstMonthHo l = request.form("F irstMonthHol")
strFirstYearHol = request.form("F irstYearHol")
strLastDayHol = request.form("L astDayHol")
strLastMonthHol = request.form("L astMonthHol")
strLastYearHol = request.form("L astYearHol")
strNoDaysOff = request.form("N oDaysOff")
strHalfDay = request.form("H alfDay")
strHalfDayPerio d = request.form("H alfDayPeriod")
strFurtherComme nts = request.form
("FurtherComme nts")
strConfirmEmail = request.form("C onfirmEmail")
strTheDate = Date
strTheTime = Time

Set objCDO = Server.CreateOb ject("CDONTS.Ne wMail")

objCDO.From = "we*****@abc.co m"

objCDO.To = "ho**********@a bc.com"

objCDO.Cc = strConfirmEmail

objCDO.Subject = "Driver Holiday Application"

objCDO.Body = "<html><body><h 2>Driver Holiday
Application: </h2>" _
& "<font face='Courier'> <font size='1'><b>For m
Submitted..... ....</b> " & strTheDate & " at " &
strTheTime & " <br><br>" _
& "<b>Name....... ............</b> " &
strApplicantNa me & " <br>" _
& "<b>Applica nt Location.....</b> " & strLocation & "<br>" _
& "<b>Contact Number......... </b> " & strPhoneNumber
& " <br>" _
& "<b>Line Manager........ ...</b> " &
strLineManager Name & " <br>" _
& "<b>First day of Holiday...</b> " & strFirstDayHol
& " " & strFirstMonthHo l & " " & strFirstYearHol & " <br>"_
& "<b>Last day of Holiday....</b> " & strLastDayHol
& " " & strLastMonthHol & " " & strLastYearHol & " <br>" _
& "<b>Total working days off.</b> " & strNoDaysOff
& " Day(s)" & " + " & strHalfDay & " " & "Half Day(s)" & "(" & strHalfDayPerio d & ")" &" <br>" _
& "<b><br>Confirm ation sent to...</b> " &
strConfirmEmai l & " <br>" _
& "<p><u><b>Furth er Comments:</u></b><br><br> " &
strFurtherComm ents & "</p>" _
& Comments _
& "</body></html>"

objCDO.BodyForm at = 0

objCDO.MailForm at = 0

objCDO.Send

Set objCDO = Nothing

Response.Redire ct "dri_confirm.ht m"
%>
.

Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2878
by: The Plankmeister | last post by:
Hi... What's the best method of validating input characters? I would like to prevent users submitting exotic characters (such as those acquired on Windows Systems by pressing ALT+) and thought a way of doing this would be to compare the submitted strings with the array keys returned by get_html_translation_table(HTML_ENTITIES), but padding...
3
13988
by: Mark | last post by:
Hi, Im trying to validate a form, all the validating works apart from one field. This particular field must consist of the first 2 characters as letters, & the following 5 as numbers. And if it dosent meet these requirments an error message will be displayed. I have pasted the code (and highlighted the relevant parts) below in the hope that...
2
2112
by: Chris Dunaway | last post by:
I have a form with a textbox and numerous panels, buttons and other controls. I have handled the textbox Validating and Validated events. The textbox will hold a filename. In the validating event, I check that the string in the textbox is a file that exists or whether or not the string is blank and display a message box in either case. I...
0
2456
by: Matthew | last post by:
All, I have searched google and the newsgroups but can't find anything the same as what I am experiencing (though I may have missed something). I have controls (textboxes) within UserControls which are not behaving as I would expect. Specifically, if there is a command button external to the usercontrol which is activated by a shortcut...
0
2425
by: Gary Shell | last post by:
I am experiencing some strange behavior between a UserControl's validating event and a treeview control. Initially, I thought it was related to an issue in the Knowledgebase article 810852 (http://support.microsoft.com/kb/810852), but then I realized that the hotfix mentioned was in .Net v1.1, which I am using. I took the sample from that...
1
5912
by: platostoteles | last post by:
Hallo NG, I am new to JavaScript and would really appreciate any help to solve my problem. I am using the blow code in my form to validate form fields. What I would like to accomplish is that if when the list/menu (attribute6) value is "Ja" then to make the TextField Pas Nr (attribute4) required. And if when the list/menu (attribute6)...
21
9135
by: Darin | last post by:
I have a form w/ a textbox and Cancel button on it. I have a routine to handle textbox.validating, and I have the form setup so the Cancel button is the Cancel button. WHen the user clicks on the cancel button, the textbox.validating is being called. I don't want it to be since they are exiting the screen the validation doesn't have to be...
4
2465
by: easoftware | last post by:
I am using VS .Net 2003 and VB. I have an app with one parent and two Mdi child forms. I need to validate data in the Mdi form. The Form.Validating event works when I try to close a Mdi form, but not when I try to switch form one Mdi form to the other. I tried to add code to MdiForm1's Deactivate event: Private Sub...
1
3783
by: =?Utf-8?B?bGpsZXZlbmQy?= | last post by:
I've noticed that controls do not raise a Validating event if they are contained in a ToolStripDropDown via a ToolStripControlHost item. Please run the following sample and follow the instructions on the form to reproduce this issue: ------------------------------------ Public Class Form1 Inherits Windows.Forms.Form
0
7475
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...
0
7409
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...
0
7918
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7766
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5981
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4958
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...
0
3446
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1897
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
1
1022
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.