how one can validate the HTML form fields before submitting them to database. my scenario is:-
In html page,there are some form fields like name,password,age,email and one submit button also.When i click on submit button all the form fields are supposed to get validated thru java-script function.In the form action="/FDTest.do" tag all the details entered by user are supposed to store in Database for that, code is written in 'FDTest.java' file.
And in 'web.xml' file is given.
any thing is wrong in this code?
and is there any other way to map the url-pattern with servlet class? and is it necessary to give the same string at form action="XXX" and url-pattern XXX.
even i tried class name with the package name also. but i want to know that is it possible to validate the data entered by user and then forward the data to java class to submit into the database? by clicking on submit button. and form action="FDTest.do" is it ok? or need to change it?
Ashok<br /> <br />SCJP 91%<br />SCWCD 88%
Joined: Jun 28, 2007
yes, i mean that.once all fields are validated then only the data is supposed to be submitted to database.
but my doubt is....... what should be written in form action attribute? and what should be the form field for submit, is it submit button or simply a button? then what should be the java-script method? is it onsubmit() or onclick()? could you help me to get solution?
one more thing i required is, how both actions will be done at a time? like..clicking on submit-button/normal button and sending the details through form action to other java class. how both actions can be done at a time?
You really (!) shouldn't rely on client-side validation of input. There's nothing wrong with validating input client-side to promote fast feedback to the user. However, in terms of security client-side validation of input is a BIG no-no, because an attacker can easily bypass these checks. You should always validate (user) input server-side. [ April 07, 2008: Message edited by: Jelle Klap ]
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Originally posted by Jelle Klap: You really (!) shouldn't rely on client-side validation of input. There's nothing wrong with validating input client-side to promote fast feedback to the user. However, in terms of security client-side validation of input is a BIG no-no, because an attacker can easily bypass these checks. You should always validate (user) input server-side.
Jelle Klap is 100% correct. Print out this post and put it up on your wall.
Data needs to be validated on the server regardless of whether it was already validated on the client or not. [ April 07, 2008: Message edited by: Bear Bibeault ]
You have asked one doubt like is it both actions are working at the same time , i.e onsubmit and onclick
No , both are not work at the same time , either onsubmit or onclick will do action .
If suppose you want to use onsubmit you just keep like this input type = "submit" for onclick input type="button"
If you are using action so you have to use onsubmit only then only you are form fields will be validated at that time onclick will not use as my understand why I am saying this i have faced the same problem .
I hope You can understand onsumbit="return scriptmethod();"