View Full Version : help with form validation
brad_nelson1
09-02-2001, 10:48 PM
Hey guys I have a problem with form validation.
I am running a form that collects the data and parses the data to a mysql database. I added a javascript that checks to make sure the email field was filled out correcty. Now i want other certain fields (name, address, city etc) to be validated. Whats the best way to do this?
here is what the form line looks like:
<FORM method="POST" action="/secure2/ib_parseorder.php" onsubmit="return checkbae()" language="JavaScript" name="validation">
thanks for any help!
Brad
Dr. Web
09-03-2001, 12:25 AM
how about showing us the entire web page code.
Javascript can handle about any verification you want. There are plenty of pre-written scripts.... and the members here can help write any custom ones you might need.
Some links to get you started... (http://www.volcanic-design.com/volc_links.htm)
scoutt
09-03-2001, 03:02 PM
if you are using php, then why don't you check for validation with that instead of javascript.
Gregory_Snyder
09-10-2001, 02:59 AM
This is what I use on all my forms:
<html>
<head>
<script language="JavaScript" src="dir/dir/name.js"></script>
</head>
<form name="form" onSubmit="return functionName()" action="http://subdomain.server.tld/cgi-bin/script.pl" method=POST>
the *.js file contains this:
function functionName(){
if (form.fieldOne.value == "")
{
alert("Please input what I want here.");
form.fieldOne.focus();
return (false);
}
if (form.fieldTwo.value == "")
{
alert("Please input what I want here.");
form.fieldTwo.focus();
return (false);
}
}
you can add as many fields as you want or need. you can also put the javascript in the head section of your page instead of in a .js file if you like, but i always use .js files.
hope i could help!
-greg
Gregory_Snyder
09-10-2001, 03:01 AM
i just noticed that your form tag says:
<FORM method="POST" action="/secure2/ib_parseorder.php" onsubmit="return checkbae()" language="JavaScript" name="validation">
i have never seen a form tag with a 'language' attribute...what's it there for? am i missing something?
-greg
whkoh
09-10-2001, 03:56 AM
Originally posted by Gregory_Snyder
i just noticed that your form tag says:
<FORM method="POST" action="/secure2/ib_parseorder.php" onsubmit="return checkbae()" language="JavaScript" name="validation">
i have never seen a form tag with a 'language' attribute...what's it there for? am i missing something?
-greg No, it is not an attribute of the FORM tag of the W3C (http://www.w3.org/) HTML4/HTML4.01 Recommendations.
Dr. Web
09-10-2001, 01:10 PM
Scoutt,
the advantage of using client side verifications is that they do not need a callto the server to check. Example: You fill out the form but forget to add an email address. The you hit submit, wait, PHP checks for errors, and then recreates the page with the error info, and finally sends it back to the client machine. Time cinsuming especially if the surfer makes more than 1 error. JS verifications are quick and painless, with no server calls.
Gregory,
the email verification you seek is found at www.a1javascripts.com under forms. Lets us know if you have any problems using it, I found it painless.
scoutt
09-10-2001, 02:26 PM
thanks Dr. I see what you are saying, it's just that I was thinking since he might be calling a php script then it wouldn't matter would it?
anyway I grabbed that code for the js form validation, thanks Gregory :)
Dr. Web
09-10-2001, 03:10 PM
yes, but any server calls are 'expensive' on a time basis.
if the surfer forgets to enter his email... one server call needed. then he forgets the @ symbol. two calls. Perhaps he forgets to entter his name. three calls. lots of time lost.
I know you are thinking "What kind of idiot would forget all that stuff?"
People on the web will fill out a form with as few fields as possible, as fast as possible. They are going to mess it up, and you have go to make it painless for them to recover after they do. The more time it takes to fix a mistake, the less likely they will do so.
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.