469,306 Members | 1,935 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,306 developers. It's quick & easy.

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 2189
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by The Plankmeister | last post: by
2 posts views Thread by Chris Dunaway | last post: by
reply views Thread by Gary Shell | last post: by
1 post views Thread by platostoteles | last post: by
4 posts views Thread by easoftware | last post: by
1 post views Thread by =?Utf-8?B?bGpsZXZlbmQy?= | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Geralt96 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.