|
 |
asp_databases thread: Validate Data Problem
Message #1 by "Kevin Slinkman" <KevinS@R...> on Mon, 18 Nov 2002 18:11:52
|
|
I am building and ASP page to input data into an Access database. I would
like to validate data as part of the input process. I am using the code
from Chapter 10 pages 391 to 394 as a model. I am particularly using the
section on page 393. I am trying to check input for zero length strings;
I want to check each field for the string length. Then if the string
length equals zero set the focus to the appropriate field. All this works
fine except that the application jumps to the next page after it sets the
focus. This is the code that I am using:
<html>
<head>
<title>Employee Ticket Pool - Ticket Additions</title>
</head>
<body>
<h2>Ticket Pool</h2>
<p><font size="3" color="red">Select Date of Game</font></p>
<form method="POST" action="AddGameResponse1.ASP" NAME = frmAddGame>
<p>Please enter your name : <input type="text" name="EmpName"
size="25"></p>
<p>Please enter your Email Address : <input type="text" name="EMail"
size="25"></p>
<p>Please enter game date : <input type="text" name="Date"
size="10"></p>
<p>Please enter Opponent : <input type="text" name="Opponent"
size="25"></p>
<p>Please enter Section: <input type="text" name="Section"
size="25"></p>
<p>Please enter Row : <input type="text" name="Row" size="25"></p>
<p>Please enter Seat : <input type="text" name="Seat" size="25"></p>
<p><input type="submit" Name="btnSubmit" value="Submit"><input
type="reset" value="Reset"></p>
</form>
</body>
</html>
<script language=vbscript>
Sub btnSubmit_OnClick()
'Validate all fields contain data
If Len(frmAddGame.EmpName.value) = 0 Then
Alert "You must enter your name"
frmAddGame.EmpName.focus
Exit Sub
ElseIf Len(frmAddGame.EMail.value) = 0 Then
Alert "You must enter An Email Address"
frmAddGame.EMail.focus
Exit Sub
ElseIf Len(frmAddGame.Date.value) = 0 Then
Alert "You must enter a date"
frmAddGame.Date.focus
Exit Sub
ElseIf Len(frmAddGame.Opponent.value) = 0 Then
Alert "You must enter an opponent"
frmAddGame.Opponent.focus
Exit Sub
ElseIf Len(frmAddGame.Section.value) = 0 Then
Alert "You must enter a section"
frmAddGame.Section.focus
Exit Sub
ElseIf Len(frmAddGame.Row.value) = 0 Then
Alert "You must enter a row"
frmAddGame.Row.focus
Exit Sub
ElseIf Len(frmAddGame.Seat.value) = 0 Then
Alert "You must enter a seat"
frmAddGame.Seat.focus
Exit Sub
End If
'If we make this far then submit the form
Call frmAddGame.submit()
End Sub
</script>
I am sure I am over looking something here but, what is it?
Message #2 by "Peter Foti (PeterF)" <PeterF@S...> on Mon, 18 Nov 2002 13:26:23 -0500
|
|
Note that this is not an ASP question.
Also, by using VBScript as the language for your script tag, you are
limiting yourself to IE browsers only. If you want to do client side
validation, then you should use Javascript instead. A better solution (in
my opinion) is to do the validation on the server side. Then you don't need
to worry what browser the client is using and whether they have scripting
enabled, and you can be sure that only validated data is being stored in the
database. You can't be sure otherwise.
To answer your question, though, your form submit button should not be of
type "Submit". Make it type "button" instead.
Regards,
Peter
-----Original Message-----
From: Kevin Slinkman [mailto:KevinS@R...]
Sent: Monday, November 18, 2002 6:12 PM
To: ASP Databases
Subject: [asp_databases] Validate Data Problem
I am building and ASP page to input data into an Access
database. I would
like to validate data as part of the input process. I am using
the code
from Chapter 10 pages 391 to 394 as a model. I am particularly
using the
section on page 393. I am trying to check input for zero
length strings;
I want to check each field for the string length. Then if the string
length equals zero set the focus to the appropriate field. All
this works
fine except that the application jumps to the next page after
it sets the
focus. This is the code that I am using:
<html>
<head>
<title>Employee Ticket Pool - Ticket Additions</title>
</head>
<body>
<h2>Ticket Pool</h2>
<p><font size="3" color="red">Select Date of Game</font></p>
<form method="POST" action="AddGameResponse1.ASP" NAME = frmAddGame>
<p>Please enter your name : <input type="text" name="EmpName"
size="25"></p>
<p>Please enter your Email Address : <input type="text"
name="EMail"
size="25"></p>
<p>Please enter game date : <input type="text" name="Date"
size="10"></p>
<p>Please enter Opponent : <input type="text" name="Opponent"
size="25"></p>
<p>Please enter Section: <input type="text" name="Section"
size="25"></p>
<p>Please enter Row : <input type="text" name="Row" size="25"></p>
<p>Please enter Seat : <input type="text" name="Seat"
size="25"></p>
<p><input type="submit" Name="btnSubmit" value="Submit"><input
type="reset" value="Reset"></p>
</form>
</body>
</html>
<script language=vbscript>
Sub btnSubmit_OnClick()
'Validate all fields contain data
If Len(frmAddGame.EmpName.value) = 0 Then
Alert "You must enter your name"
frmAddGame.EmpName.focus
Exit Sub
ElseIf Len(frmAddGame.EMail.value) = 0 Then
Alert "You must enter An Email Address"
frmAddGame.EMail.focus
Exit Sub
ElseIf Len(frmAddGame.Date.value) = 0 Then
Alert "You must enter a date"
frmAddGame.Date.focus
Exit Sub
ElseIf Len(frmAddGame.Opponent.value) = 0 Then
Alert "You must enter an opponent"
frmAddGame.Opponent.focus
Exit Sub
ElseIf Len(frmAddGame.Section.value) = 0 Then
Alert "You must enter a section"
frmAddGame.Section.focus
Exit Sub
ElseIf Len(frmAddGame.Row.value) = 0 Then
Alert "You must enter a row"
frmAddGame.Row.focus
Exit Sub
ElseIf Len(frmAddGame.Seat.value) = 0 Then
Alert "You must enter a seat"
frmAddGame.Seat.focus
Exit Sub
End If
'If we make this far then submit the form
Call frmAddGame.submit()
End Sub
</script>
I am sure I am over looking something here but, what is it?
Message #3 by "Drew, Ron" <RDrew@B...> on Mon, 18 Nov 2002 13:28:45 -0500
|
|
I would use Javascript to keep the validation on the client so less
traffic to the server. Just put an onsubmit on the form statement
(return looks for a true or false) and execute the Javascript. Here is
an example of some validation (I deleted a lot so this email didn't turn
out to be a book...cut and paste and change it to your liking.
<head>
<script language=3D"JavaScript">
<!--
function CheckForm() {
if (document.formmail.VendorName.value =3D=3D "")
{
alert("Please enter a value for the \"Name\" field.");
document.formmail.VendorName.focus();
return (false);
}
if (document.formmail.Terms.value =3D=3D "")
{
alert("Please enter a value for the \"Terms\" field.");
document.formmail.Terms.focus();
return (false);
}
return (true);
}
//-->
</script>
<body>
<FORM name=3D"formmail" METHOD=3D"post" ACTION=3D"Mailit.asp"
onsubmit=3D"return CheckForm()">
-----Original Message-----
From: Kevin Slinkman [mailto:KevinS@R...]
Sent: Monday, November 18, 2002 1:12 PM
To: ASP Databases
Subject: [asp_databases] Validate Data Problem
I am building and ASP page to input data into an Access database. I
would
like to validate data as part of the input process. I am using the code
from Chapter 10 pages 391 to 394 as a model. I am particularly using
the
section on page 393. I am trying to check input for zero length
strings;
I want to check each field for the string length. Then if the string
length equals zero set the focus to the appropriate field. All this
works
fine except that the application jumps to the next page after it sets
the
focus. This is the code that I am using:
<html>
<head>
<title>Employee Ticket Pool - Ticket Additions</title>
</head>
<body>
<h2>Ticket Pool</h2>
<p><font size=3D"3" color=3D"red">Select Date of Game</font></p>
<form method=3D"POST" action=3D"AddGameResponse1.ASP" NAME =3D
frmAddGame>
<p>Please enter your name : <input type=3D"text" name=3D"EmpName"
size=3D"25"></p>
<p>Please enter your Email Address : <input type=3D"text"
name=3D"EMail"
size=3D"25"></p>
<p>Please enter game date : <input type=3D"text" name=3D"Date"
size=3D"10"></p>
<p>Please enter Opponent : <input type=3D"text" name=3D"Opponent"
size=3D"25"></p>
<p>Please enter Section: <input type=3D"text" name=3D"Section"
size=3D"25"></p>
<p>Please enter Row : <input type=3D"text" name=3D"Row"
size=3D"25"></p>
<p>Please enter Seat : <input type=3D"text" name=3D"Seat"
size=3D"25"></p>
<p><input type=3D"submit" Name=3D"btnSubmit" value=3D"Submit"><input
type=3D"reset" value=3D"Reset"></p>
</form>
</body>
</html>
<script language=3Dvbscript>
Sub btnSubmit_OnClick()
'Validate all fields contain data
If Len(frmAddGame.EmpName.value) =3D 0 Then
Alert "You must enter your name"
frmAddGame.EmpName.focus
Exit Sub
ElseIf Len(frmAddGame.EMail.value) =3D 0 Then
Alert "You must enter An Email Address"
frmAddGame.EMail.focus
Exit Sub
ElseIf Len(frmAddGame.Date.value) =3D 0 Then
Alert "You must enter a date"
frmAddGame.Date.focus
Exit Sub
ElseIf Len(frmAddGame.Opponent.value) =3D 0 Then
Alert "You must enter an opponent"
frmAddGame.Opponent.focus
Exit Sub
ElseIf Len(frmAddGame.Section.value) =3D 0 Then
Alert "You must enter a section"
frmAddGame.Section.focus
Exit Sub
ElseIf Len(frmAddGame.Row.value) =3D 0 Then
Alert "You must enter a row"
frmAddGame.Row.focus
Exit Sub
ElseIf Len(frmAddGame.Seat.value) =3D 0 Then
Alert "You must enter a seat"
frmAddGame.Seat.focus
Exit Sub
End If
=09
'If we make this far then submit the form
Call frmAddGame.submit()
End Sub
</script>
I am sure I am over looking something here but, what is it?
Message #4 by "Kevin Slinkman" <KevinS@R...> on Mon, 18 Nov 2002 19:35:28
|
|
>
> I am building and ASP page to input data into an Access database. I
would
l> ike to validate data as part of the input process. I am using the code
f> rom Chapter 10 pages 391 to 394 as a model. I am particularly using
the
s> ection on page 393. I am trying to check input for zero length
strings;
I> want to check each field for the string length. Then if the string
l> ength equals zero set the focus to the appropriate field. All this
works
f> ine except that the application jumps to the next page after it sets
the
f> ocus. This is the code that I am using:
> <html>
<> head>
<> title>Employee Ticket Pool - Ticket Additions</title>
<> /head>
<> body>
<> h2>Ticket Pool</h2>
<> p><font size="3" color="red">Select Date of Game</font></p>
> <form method="POST" action="AddGameResponse1.ASP" NAME = frmAddGame>
> <p>Please enter your name : <input type="text" name="EmpName"
s> ize="25"></p>
> <p>Please enter your Email Address : <input type="text"
name="EMail"
s> ize="25"></p>
> <p>Please enter game date : <input type="text" name="Date"
s> ize="10"></p>
> <p>Please enter Opponent : <input type="text" name="Opponent"
s> ize="25"></p>
> <p>Please enter Section: <input type="text" name="Section"
s> ize="25"></p>
> <p>Please enter Row : <input type="text" name="Row" size="25"></p>
> <p>Please enter Seat : <input type="text" name="Seat"
size="25"></p>
> <p><input type="submit" Name="btnSubmit" value="Submit"><input
t> ype="reset" value="Reset"></p>
> </form>
<> /body>
<> /html>
> <script language=vbscript>
> Sub btnSubmit_OnClick()
> 'Validate all fields contain data
> If Len(frmAddGame.EmpName.value) = 0 Then
> Alert "You must enter your name"
> frmAddGame.EmpName.focus
> Exit Sub
> ElseIf Len(frmAddGame.EMail.value) = 0 Then
> Alert "You must enter An Email Address"
> frmAddGame.EMail.focus
> Exit Sub
> ElseIf Len(frmAddGame.Date.value) = 0 Then
> Alert "You must enter a date"
> frmAddGame.Date.focus
> Exit Sub
> ElseIf Len(frmAddGame.Opponent.value) = 0 Then
> Alert "You must enter an opponent"
> frmAddGame.Opponent.focus
> Exit Sub
> ElseIf Len(frmAddGame.Section.value) = 0 Then
> Alert "You must enter a section"
> frmAddGame.Section.focus
> Exit Sub
> ElseIf Len(frmAddGame.Row.value) = 0 Then
> Alert "You must enter a row"
> frmAddGame.Row.focus
> Exit Sub
> ElseIf Len(frmAddGame.Seat.value) = 0 Then
> Alert "You must enter a seat"
> frmAddGame.Seat.focus
> Exit Sub
> End If
>
> 'If we make this far then submit the form
> Call frmAddGame.submit()
>
> End Sub
> </script>
>
> I am sure I am over looking something here but, what is it?
Message #5 by "Kevin Slinkman" <KevinS@R...> on Mon, 18 Nov 2002 19:37:41
|
|
>
Even if this was not an ASP question I do appreciate the help thanks. And
I will also consider your advice about client side validation.
> I am building and ASP page to input data into an Access database. I
would
l> ike to validate data as part of the input process. I am using the code
f> rom Chapter 10 pages 391 to 394 as a model. I am particularly using
the
s> ection on page 393. I am trying to check input for zero length
strings;
I> want to check each field for the string length. Then if the string
l> ength equals zero set the focus to the appropriate field. All this
works
f> ine except that the application jumps to the next page after it sets
the
f> ocus. This is the code that I am using:
> <html>
<> head>
<> title>Employee Ticket Pool - Ticket Additions</title>
<> /head>
<> body>
<> h2>Ticket Pool</h2>
<> p><font size="3" color="red">Select Date of Game</font></p>
> <form method="POST" action="AddGameResponse1.ASP" NAME = frmAddGame>
> <p>Please enter your name : <input type="text" name="EmpName"
s> ize="25"></p>
> <p>Please enter your Email Address : <input type="text"
name="EMail"
s> ize="25"></p>
> <p>Please enter game date : <input type="text" name="Date"
s> ize="10"></p>
> <p>Please enter Opponent : <input type="text" name="Opponent"
s> ize="25"></p>
> <p>Please enter Section: <input type="text" name="Section"
s> ize="25"></p>
> <p>Please enter Row : <input type="text" name="Row" size="25"></p>
> <p>Please enter Seat : <input type="text" name="Seat"
size="25"></p>
> <p><input type="submit" Name="btnSubmit" value="Submit"><input
t> ype="reset" value="Reset"></p>
> </form>
<> /body>
<> /html>
> <script language=vbscript>
> Sub btnSubmit_OnClick()
> 'Validate all fields contain data
> If Len(frmAddGame.EmpName.value) = 0 Then
> Alert "You must enter your name"
> frmAddGame.EmpName.focus
> Exit Sub
> ElseIf Len(frmAddGame.EMail.value) = 0 Then
> Alert "You must enter An Email Address"
> frmAddGame.EMail.focus
> Exit Sub
> ElseIf Len(frmAddGame.Date.value) = 0 Then
> Alert "You must enter a date"
> frmAddGame.Date.focus
> Exit Sub
> ElseIf Len(frmAddGame.Opponent.value) = 0 Then
> Alert "You must enter an opponent"
> frmAddGame.Opponent.focus
> Exit Sub
> ElseIf Len(frmAddGame.Section.value) = 0 Then
> Alert "You must enter a section"
> frmAddGame.Section.focus
> Exit Sub
> ElseIf Len(frmAddGame.Row.value) = 0 Then
> Alert "You must enter a row"
> frmAddGame.Row.focus
> Exit Sub
> ElseIf Len(frmAddGame.Seat.value) = 0 Then
> Alert "You must enter a seat"
> frmAddGame.Seat.focus
> Exit Sub
> End If
>
> 'If we make this far then submit the form
> Call frmAddGame.submit()
>
> End Sub
> </script>
>
> I am sure I am over looking something here but, what is it?
Message #6 by "Ken Schaefer" <ken@a...> on Tue, 19 Nov 2002 15:37:36 +1100
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
From: "Drew, Ron" <RDrew@B...>
Subject: [asp_databases] RE: Validate Data Problem
I would use Javascript to keep the validation on the client so less
traffic to the server. Just put an onsubmit on the form statement
(return looks for a true or false) and execute the Javascript. Here is
an example of some validation (I deleted a lot so this email didn't turn
out to be a book...cut and paste and change it to your liking.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Validation on the client-side must be used only for the benefit of the
client. It should *not* be used to protect your application as it is trivial
to subvert.
All data should be validated on the server to prevent SQL Injection and
Cross-Site Scripting attacks...
Cheers
Ken
|
|
 |