-
server side validation vs. client side validation
Hi all.
I want to know that what the difference between server side validation and
client side validation is?Can every one build a scenariofor them when sending
data from a form to server? And also how can distinguish them?What is the
syntaxes for them?
TIA
s
-
Re: server side validation vs. client side validation
Client side validation runs in the browser to check that the form values are
of the correct type. JavaScript should always be used on the client side
since it is supported by both Netscape and IE. (VBScript is supported only
by IE).
Server side validation checks the code that is submitted to make sure it
is correct. Good applications will use both server and client validation.
One reason for this is that it would be possible for someone else to write
a form that calls your .asp page - they might not use client side validation
and might throw in garbage data.
Here is a brief example that uses client code to make sure that required
fields have been entered. Normally client side code gets much more detailed
because you want to check that a phone number looks like a phone number,
an email address looks like an email address, etc. Any good book on JavaScript
- like O'Reilly's JavaScript, The Definitive Guide - goes into the details.
Also note that I didn't include any server validation code in this example.
<%
if request.form("task") = "Submit Form" then
' Form processing code goes here.
response.write("This is the data you submitted:<br><br>")
response.write(request.form("field1") & "<br>")
response.write(request.form("field2") & "<br>")
response.write(request.form("field3") & "<br>")
response.write(request.form("field4") & "<br>")
end if
%>
<html>
<head>
<title>Page Title</title>
<script language="JavaScript" type="text/javascript">
// fieldChecker checks to make sure that all required fields have been filled
out.
function fieldChecker(f) {
for (var x=0;x<f.length - 2;x++) {
if (f.elements[x].optional == null) {
if (f.elements[x].value == '') {
alert('This field is required.');
f.elements[x].focus();
return false;
}
}
}
return true;
}
</script>
</head>
<body>
<form name="Sample" method="post" action="sample.asp" onSubmit="this.field3.optional=true;
this.field4.optional=true; return fieldChecker(this);">
<br>
Field 1: (Required) <input type="text" name="field1"><br><br>
Field 2: (Required) <input type="text" name="field2"><br><br>
Field 3: <input type="text" name="field3"><br><br>
Field 4: <input type="text" name="field4"><br><br>
<input type="submit" name="task" value="Submit Form">
</form>
</body>
</html>
"s" <s_mahd@yahoo.com> wrote:
>
>Hi all.
>I want to know that what the difference between server side validation
and
>client side validation is?Can every one build a scenariofor them when sending
>data from a form to server? And also how can distinguish them?What is the
>syntaxes for them?
>TIA
>s
-
Re: server side validation vs. client side validation
As Dan said, you should always write server-side validation code even if you
validate the data on the client. But the *reason* for writing client-side
validation is to avoid the round-trip to the server that would otherwise be
required to validate the data. In other words, if the user enters invalid
data, it's much more efficient and user-friendly to trap the error *before*
sending the data to the server, where--if the data is invalid--you'll have
to rebuild the page and maintain the page state as well so that the user can
fix the invalid value.
"s" <s_mahd@yahoo.com> wrote in message news:3b8e2293$1@news.devx.com...
>
> Hi all.
> I want to know that what the difference between server side validation
and
> client side validation is?Can every one build a scenariofor them when
sending
> data from a form to server? And also how can distinguish them?What is the
> syntaxes for them?
> TIA
> s
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|