473,700 Members | 2,641 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 2366
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
2891
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 this array out with all the remaining normal keyboard characters. But... am I reinventing the...
3
14012
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 someone can help me out with this. Ive been trying to suss it out all week & it's driving me nuts!...
2
2125
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 also call e.Cancel so that the value will be corrected. However, certain buttons on the form...
0
2465
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 key (eg Alt-B), the command button Click event handler code 'executes' even though the textbox set...
0
2435
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 article and recreated the situation I see in my application. (Code included below.) If you run the...
1
5932
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) value is "Nee" to make the TextField Pas Nr (attribute4) not required.
21
9186
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 done. How can I do that.
4
2477
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 MidForm1_Deactivate(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Deactivate Dim TempE As...
1
3790
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
8649
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,...
0
9219
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8975
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7819
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6564
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
5904
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
4660
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3097
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
2395
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.