473,382 Members | 1,480 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

best form validation

pradeepjain
563 512MB
Hii guys,
My site has whole lots of forms...i wanted to know which is the best method for form validation.

say using ajax or javascript and server side or any other..if there is any example it would be better
Dec 1 '08 #1
12 2453
Dormilich
8,658 Expert Mod 8TB
If I have to do form validation I usually run a client side validation (JS) so that the user may correct the entries and a server side validation to check if really all fields were filled correctly.
Dec 1 '08 #2
pradeepjain
563 512MB
I am also following the same thing as of now..i was thinking of Ajax ...but i got answers that
it uses lots of server resourse ..
Dec 1 '08 #3
dlite922
1,584 Expert 1GB
@pradeepjain
You don't need ajax for validation. If you've got a long form, I would assist the user along with JavaScript to get as much of the form right as possible. At that point I would use the bandwidth to validate. If my code is right and it's a legitimate user, I shouldn't get any failed validations server side, those people who are going to hack it, will get my server-side error message.

If you've got a short forum and don't mind the traffic/resource of submitting the form for validation, I would just do it that way. Why do the wort twice.

Second reason to do it on client-side too is for usability. It's so nice to have a phone number formatted and counted to make sure I didn't miss a digit. Some forms put a green check mark next to each field I fill out if its correct and a red X for those that are incorrect after I've left that field.


Dan
Dec 1 '08 #4
pradeepjain
563 512MB
yup the thing u told putting x mark and tick mark needs ajax scripting i guess
Dec 1 '08 #5
dlite922
1,584 Expert 1GB
@pradeepjain
no not really. Depends on what your validating. If your validating an email address, you can use JavaScript since you already know what an email "should" look like.

But for example you need to check if a username has been taken, you need to query your database, and for this you need Ajax.




Dan
Dec 1 '08 #6
pradeepjain
563 512MB
my form does need to validate only few fields like phone,email..etc....i use pop up msg on submit ......can u show me an example for wht u told like x mark and tick mark with javascripts....
Dec 1 '08 #7
dlite922
1,584 Expert 1GB
it is basic JavaScript really, there's no trick. All your doing is changing the display value of an image. (See Google for more info) You have two images that are off by default. (Display: none with CSS). With javascript you turn on the one that corresponds to the validation.

simple example:
Expand|Select|Wrap|Line Numbers
  1. if(valid)
  2. {
  3.   document.getElementById('emailImageCheck').style.display = "block"; // or inline 
  4. }  
  5. else
  6. {
  7.   document.getElementById('emailImageRedX').style.display = "block"; // or 
  8. }
  9.  



Dan
Dec 1 '08 #8
pradeepjain
563 512MB
i guess u were talking of form like this
Javascript form validation - doing it right

i really dont understand without any examples :(
Dec 1 '08 #9
dlite922
1,584 Expert 1GB
@pradeepjain
Yes, like that. except instead of red text you would do the lines I typed in my previous post.

You learn coding by trying. Beginning coders copy and paste. Then you change the code. And then you learn to memorize and use references and Google less and less.

This is a path everybody takes. No one learns outright code by memorization.


Dan
Dec 1 '08 #10
Markus
6,050 Expert 4TB
You need a combination of both Javascript, although it isn't required, and PHP. If you're going to use one and not the other, then you must use PHP. The reason to this is: Javascript is not always enabled on the browser, and if your validation relies on javascript, in a browser that doesn't have it enabled, your validation is useless.
Dec 1 '08 #11
pbmods
5,821 Expert 4TB
Moving to the Javascript forum for now.
Dec 2 '08 #12
acoder
16,027 Expert Mod 8TB
pradeepjain,

post your code and explain what you've tried and the parts you're struggling with. In the link, you can just view the source to see the code and adapt it to your requirements.
Dec 2 '08 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Mike Button | last post by:
Hello all, I am really really desperate on what I should do, and I am asking for help from anyone in this newsgroup, here's the situation: I am creating a form that is being run on a server...
16
by: Hosh | last post by:
I have a form on a webpage and want to use JavaScript validation for the form fields. I have searched the web for form validation scripts and have come up with scripts that only validate...
9
by: julie.siebel | last post by:
Hello all! As embarrassing as it is to admit this, I've been designing db driven websites using javascript and vbscript for about 6-7 years now, and I am *horrible* at form validation. To be...
3
by: Furty | last post by:
Hi, I'm looking for the best practice for creating a generic data validation implementation for my data bound business objects. I currently have a business object base class implementing the...
7
by: h7qvnk7q001 | last post by:
I'm trying to implement a simple server-side form validation (No Javascript). If the user submits a form with errors, I want to redisplay the same form with the errors highlighted. Once the form...
1
by: Drew Wildner | last post by:
Hello grp: Given the following scenario, I'm hoping someone can suggest the best method for accomplishing xml validation. We have a system that accepts requests in the form of xml messages. ...
17
by: Petyr David | last post by:
Just looking for the simplest. right now my perl script returns an error messge to the user if the date string is invalid. would like to do this before accessing the server. TX
8
by: Phil Latio | last post by:
I've been creating an application over the last few weeks and generally pleased with what I have produced but one area is irritating me, form validation. At the moment the forms are simply...
0
by: shival329 | last post by:
Hi, As we know there are a lot of ways to navigate to the another page such as using Response.Redirect, Server.Transfer,Server.Execute,& using context.handler . In all these cases we want to...
12
by: Gustaf | last post by:
I've been working on a membership form for a while, and find it very tedious to get an acceptable level of form validation. A web search for solutions revealed some home-brewed solutions, such as...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.