473,394 Members | 1,854 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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 strApplicantName
Dim strPhoneNumber
Dim strLocation
Dim strLineManagerName
Dim strFirstDayHol
Dim strFirstMonthHol
Dim strFirstYearHol
Dim strLastDayHol
Dim strLastMonthHol
Dim strLastYearHol
Dim strNoDaysOff
Dim strHalfDay
Dim strHalfDayPeriod
Dim strFurtherComments
Dim strConfirmEmail
Dim strTheDate
Dim strTheTime
Dim objCDO

strApplicantName = request.form("ApplicantName")
strPhoneNumber = request.form("PhoneNumber")
strLocation = request.form("Location")
strLineManagerName = request.form
("LineManagerName")
strFirstDayHol = request.form("FirstDayHol")
strFirstMonthHol = request.form("FirstMonthHol")
strFirstYearHol = request.form("FirstYearHol")
strLastDayHol = request.form("LastDayHol")
strLastMonthHol = request.form("LastMonthHol")
strLastYearHol = request.form("LastYearHol")
strNoDaysOff = request.form("NoDaysOff")
strHalfDay = request.form("HalfDay")
strHalfDayPeriod = request.form("HalfDayPeriod")
strFurtherComments = request.form
("FurtherComments")
strConfirmEmail = request.form("ConfirmEmail")
strTheDate = Date
strTheTime = Time

Set objCDO = Server.CreateObject("CDONTS.NewMail")

objCDO.From = "we*****@abc.com"

objCDO.To = "ho**********@abc.com"

objCDO.Cc = strConfirmEmail

objCDO.Subject = "Driver Holiday Application"

objCDO.Body = "<html><body><h2>Driver Holiday
Application:</h2>" _
& "<font face='Courier'><font size='1'><b>Form
Submitted.........</b> " & strTheDate & " at " &
strTheTime & " <br><br>" _
& "<b>Name...................</b> " &
strApplicantName & " <br>" _
& "<b>Applicant Location.....</b> " & strLocation & "
<br>" _
& "<b>Contact Number.........</b> " & strPhoneNumber
& " <br>" _
& "<b>Line Manager...........</b> " &
strLineManagerName & " <br>" _
& "<b>First day of Holiday...</b> " & strFirstDayHol
& " " & strFirstMonthHol & " " & 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)" & "
(" & strHalfDayPeriod & ")" &" <br>" _
& "<b><br>Confirmation sent to...</b> " &
strConfirmEmail & " <br>" _
& "<p><u><b>Further Comments:</u></b><br><br> " &
strFurtherComments & "</p>" _
& Comments _
& "</body></html>"

objCDO.BodyFormat = 0

objCDO.MailFormat = 0

objCDO.Send

Set objCDO = Nothing

Response.Redirect "dri_confirm.htm"
%>
Jul 19 '05 #1
4 2340
If *all* you want to do is ensure that a field is not blank then you could
do:

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

Function CheckRequestForBlanks( _
)

For Each Item in Request.Form()
If Trim(Request.Form(Item)) = "" then
CheckRequestForBlanks = True
Exit Function
End If
Next

CheckRequestForBlanks = 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 strApplicantName
: Dim strPhoneNumber
: Dim strLocation
: Dim strLineManagerName
: Dim strFirstDayHol
: Dim strFirstMonthHol
: Dim strFirstYearHol
: Dim strLastDayHol
: Dim strLastMonthHol
: Dim strLastYearHol
: Dim strNoDaysOff
: Dim strHalfDay
: Dim strHalfDayPeriod
: Dim strFurtherComments
: Dim strConfirmEmail
: Dim strTheDate
: Dim strTheTime
: Dim objCDO
:
: strApplicantName = request.form("ApplicantName")
: strPhoneNumber = request.form("PhoneNumber")
: strLocation = request.form("Location")
: strLineManagerName = request.form
: ("LineManagerName")
: strFirstDayHol = request.form("FirstDayHol")
: strFirstMonthHol = request.form("FirstMonthHol")
: strFirstYearHol = request.form("FirstYearHol")
: strLastDayHol = request.form("LastDayHol")
: strLastMonthHol = request.form("LastMonthHol")
: strLastYearHol = request.form("LastYearHol")
: strNoDaysOff = request.form("NoDaysOff")
: strHalfDay = request.form("HalfDay")
: strHalfDayPeriod = request.form("HalfDayPeriod")
: strFurtherComments = request.form
: ("FurtherComments")
: strConfirmEmail = request.form("ConfirmEmail")
: strTheDate = Date
: strTheTime = Time
:
: Set objCDO = Server.CreateObject("CDONTS.NewMail")
:
: objCDO.From = "we*****@abc.com"
:
: objCDO.To = "ho**********@abc.com"
:
: objCDO.Cc = strConfirmEmail
:
: objCDO.Subject = "Driver Holiday Application"
:
: objCDO.Body = "<html><body><h2>Driver Holiday
: Application:</h2>" _
: & "<font face='Courier'><font size='1'><b>Form
: Submitted.........</b> " & strTheDate & " at " &
: strTheTime & " <br><br>" _
: & "<b>Name...................</b> " &
: strApplicantName & " <br>" _
: & "<b>Applicant Location.....</b> " & strLocation & "
: <br>" _
: & "<b>Contact Number.........</b> " & strPhoneNumber
: & " <br>" _
: & "<b>Line Manager...........</b> " &
: strLineManagerName & " <br>" _
: & "<b>First day of Holiday...</b> " & strFirstDayHol
: & " " & strFirstMonthHol & " " & 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)" & "
: (" & strHalfDayPeriod & ")" &" <br>" _
: & "<b><br>Confirmation sent to...</b> " &
: strConfirmEmail & " <br>" _
: & "<p><u><b>Further Comments:</u></b><br><br> " &
: strFurtherComments & "</p>" _
: & Comments _
: & "</body></html>"
:
: objCDO.BodyFormat = 0
:
: objCDO.MailFormat = 0
:
: objCDO.Send
:
: Set objCDO = Nothing
:
: Response.Redirect "dri_confirm.htm"
: %>
:
:
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.ServerVariables("REQUEST_METHOD") = "POST" Then
sName = Request.Form("txtName")
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 = CheckRequestForBlanks()
If blnError Then
' there is a blank
Else
' there is no blank
End If

Function CheckRequestForBlanks( _
)

For Each Item in Request.Form()
If Trim(Request.Form(Item)) = "" then
CheckRequestForBlanks = True
Exit Function
End If
Next

CheckRequestForBlanks = 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 strApplicantName
: Dim strPhoneNumber
: Dim strLocation
: Dim strLineManagerName
: Dim strFirstDayHol
: Dim strFirstMonthHol
: Dim strFirstYearHol
: Dim strLastDayHol
: Dim strLastMonthHol
: Dim strLastYearHol
: Dim strNoDaysOff
: Dim strHalfDay
: Dim strHalfDayPeriod
: Dim strFurtherComments
: Dim strConfirmEmail
: Dim strTheDate
: Dim strTheTime
: Dim objCDO
:
: strApplicantName = request.form ("ApplicantName"): strPhoneNumber = request.form("PhoneNumber")
: strLocation = request.form("Location")
: strLineManagerName = request.form
: ("LineManagerName")
: strFirstDayHol = request.form("FirstDayHol")
: strFirstMonthHol = request.form ("FirstMonthHol"): strFirstYearHol = request.form("FirstYearHol")
: strLastDayHol = request.form("LastDayHol")
: strLastMonthHol = request.form("LastMonthHol")
: strLastYearHol = request.form("LastYearHol")
: strNoDaysOff = request.form("NoDaysOff")
: strHalfDay = request.form("HalfDay")
: strHalfDayPeriod = request.form ("HalfDayPeriod"): strFurtherComments = request.form
: ("FurtherComments")
: strConfirmEmail = request.form("ConfirmEmail")
: strTheDate = Date
: strTheTime = Time
:
: Set objCDO = Server.CreateObject("CDONTS.NewMail")
:
: objCDO.From = "we*****@abc.com"
:
: objCDO.To = "ho**********@abc.com"
:
: objCDO.Cc = strConfirmEmail
:
: objCDO.Subject = "Driver Holiday Application"
:
: objCDO.Body = "<html><body><h2>Driver Holiday
: Application:</h2>" _
: & "<font face='Courier'><font size='1'><b>Form
: Submitted.........</b> " & strTheDate & " at " &
: strTheTime & " <br><br>" _
: & "<b>Name...................</b> " &
: strApplicantName & " <br>" _
: & "<b>Applicant Location.....</b> " & strLocation & ": <br>" _
: & "<b>Contact Number.........</b> " & strPhoneNumber: & " <br>" _
: & "<b>Line Manager...........</b> " &
: strLineManagerName & " <br>" _
: & "<b>First day of Holiday...</b> " & strFirstDayHol: & " " & strFirstMonthHol & " " & 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)" & ": (" & strHalfDayPeriod & ")" &" <br>" _
: & "<b><br>Confirmation sent to...</b> " &
: strConfirmEmail & " <br>" _
: & "<p><u><b>Further Comments:</u></b><br><br> " &
: strFurtherComments & "</p>" _
: & Comments _
: & "</body></html>"
:
: objCDO.BodyFormat = 0
:
: objCDO.MailFormat = 0
:
: objCDO.Send
:
: Set objCDO = Nothing
:
: Response.Redirect "dri_confirm.htm"
: %>
:
:
.

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="JavaScript">
<!-- script start

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

if (emptyField(formObj.fname))
alert("The FIRST NAME field has been left blank and is
required.");
else if (emptyField(formObj.lname))
alert("The LAST NAME field has been left blank and is
required.");
else if (emptyField(formObj.add1))
alert("The ADDRESS1 field has been left blank and is
required.");
else if (emptyField(formObj.city1))
alert("The CITY field has been left blank and is
required.");
else if (emptyField(formObj.zipcode))
alert("The ZIP CODE field has been left blank and is
required.");
else if (emptyField(formObj.phone1))
alert("The PHONE1 field has been left blank and is
required.");
else if (!validGomail(formObj.emailadd))
alert("The Invalid EMAIL ADDRESS format, please
correct.\n\n Example:\n yo*******@company.com.");
else if (emptyField(formObj.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(textObj)
{
if (textObj.value.length == 0) return true;
for (var i=0; i<textObj.value.length; ++i) {
var ch = textObj.value.charAt(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="return validateComplete
(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 strApplicantName
Dim strPhoneNumber
Dim strLocation
Dim strLineManagerName
Dim strFirstDayHol
Dim strFirstMonthHol
Dim strFirstYearHol
Dim strLastDayHol
Dim strLastMonthHol
Dim strLastYearHol
Dim strNoDaysOff
Dim strHalfDay
Dim strHalfDayPeriod
Dim strFurtherComments
Dim strConfirmEmail
Dim strTheDate
Dim strTheTime
Dim objCDO

strApplicantName = request.form("ApplicantName")
strPhoneNumber = request.form("PhoneNumber")
strLocation = request.form("Location")
strLineManagerName = request.form
("LineManagerName")
strFirstDayHol = request.form("FirstDayHol")
strFirstMonthHol = request.form("FirstMonthHol")
strFirstYearHol = request.form("FirstYearHol")
strLastDayHol = request.form("LastDayHol")
strLastMonthHol = request.form("LastMonthHol")
strLastYearHol = request.form("LastYearHol")
strNoDaysOff = request.form("NoDaysOff")
strHalfDay = request.form("HalfDay")
strHalfDayPeriod = request.form("HalfDayPeriod")
strFurtherComments = request.form
("FurtherComments")
strConfirmEmail = request.form("ConfirmEmail")
strTheDate = Date
strTheTime = Time

Set objCDO = Server.CreateObject("CDONTS.NewMail")

objCDO.From = "we*****@abc.com"

objCDO.To = "ho**********@abc.com"

objCDO.Cc = strConfirmEmail

objCDO.Subject = "Driver Holiday Application"

objCDO.Body = "<html><body><h2>Driver Holiday
Application:</h2>" _
& "<font face='Courier'><font size='1'><b>Form
Submitted.........</b> " & strTheDate & " at " &
strTheTime & " <br><br>" _
& "<b>Name...................</b> " &
strApplicantName & " <br>" _
& "<b>Applicant Location.....</b> " & strLocation & "<br>" _
& "<b>Contact Number.........</b> " & strPhoneNumber
& " <br>" _
& "<b>Line Manager...........</b> " &
strLineManagerName & " <br>" _
& "<b>First day of Holiday...</b> " & strFirstDayHol
& " " & strFirstMonthHol & " " & 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)" & "(" & strHalfDayPeriod & ")" &" <br>" _
& "<b><br>Confirmation sent to...</b> " &
strConfirmEmail & " <br>" _
& "<p><u><b>Further Comments:</u></b><br><br> " &
strFurtherComments & "</p>" _
& Comments _
& "</body></html>"

objCDO.BodyFormat = 0

objCDO.MailFormat = 0

objCDO.Send

Set objCDO = Nothing

Response.Redirect "dri_confirm.htm"
%>
.

Jul 19 '05 #5

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

Similar topics

5
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...
3
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...
2
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...
0
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...
0
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...
1
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...
21
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...
4
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,...
1
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.