Can some one please suggest a good website to help me put in some preventative coding that will help me validate the data in my forms to prevent inaccuracies Ive looked arounf and find small code snippets in java script (ive been told not to use this is it wont work with certain browsers) but nothing major - any suggestions.
I suppose I could just use dreamweavers restrriction coding??
anyway if anyone can suggest a tutorial or give any advice let me know.
Apollogies if this is too much of a basic question
Input Form Inaccuracies
Moderator: General Moderators
If only users would understand how to fill in forms correctly.
When i am constructing forms, i design them in such a way to prevent user input errors from the outset.
One of the most common input errors is with dates as these can be entered in numerous different formats...so i usually present the user with 3 drop down menus...day, month, year...then you know exactly what you are expecting to get from the user.
If this isn't possible, next thing to do is check the user data when the form has been submitted....use REGEX or whatever you need....if error, display the form again and display error message else submit form.
Mark
When i am constructing forms, i design them in such a way to prevent user input errors from the outset.
One of the most common input errors is with dates as these can be entered in numerous different formats...so i usually present the user with 3 drop down menus...day, month, year...then you know exactly what you are expecting to get from the user.
If this isn't possible, next thing to do is check the user data when the form has been submitted....use REGEX or whatever you need....if error, display the form again and display error message else submit form.
Mark
I, for one, personally can't stand forms that dont' do client side validation. I hate having to submit my data only to find out that I missed something.
why don't you do both (JS and PHP) form validation. that way if the user doesn't have JS working on their specfific browser, you are still covering yourself by checking on the server side.
what kind of fields do you need to validate? If you can let me know a few, I can help you with the JS.
as for inserting dates to the database, you can reformat the dates very easily and then insert them using php.
why don't you do both (JS and PHP) form validation. that way if the user doesn't have JS working on their specfific browser, you are still covering yourself by checking on the server side.
what kind of fields do you need to validate? If you can let me know a few, I can help you with the JS.
as for inserting dates to the database, you can reformat the dates very easily and then insert them using php.
Code: Select all
date("Y-m-d", strototime($_POSTї'mydatefield']))- smpdawg
- Forum Contributor
- Posts: 292
- Joined: Thu Jan 27, 2005 3:10 pm
- Location: Houston, TX
- Contact:
I like doing client side validation, it saves a lot of wasted time for the user if it is done properly. Here are some liks that may help you.
http://www.peterbailey.net/fValidate/
http://developer.apple.com/internet/web ... ation.html
http://wsabstract.com/script/cutindex13.shtml
http://members.aol.com/perflunk/
http://www.peterbailey.net/fValidate/
http://developer.apple.com/internet/web ... ation.html
http://wsabstract.com/script/cutindex13.shtml
http://members.aol.com/perflunk/
this was sent to me in a PM...moving it back here to keep it in the thread.
here's a better way to do that:
untested:
the above will return one alert with all the missing stuff.
field 2 up there is how you check for numbers. To check for valid email address just search the string for a "@" and a "." and maybe make sure there's a domain extension
in the future, it would be wise to keep this stuff in the threads so that others can see the resolutions.
For starters, making it return false after one criteria is not met, is not good practice. If they have two things wrong, they won't know it until they try to submit the form twice.mohson wrote:Thanks for your reply - the only validation im doing so far is 'you have not entered certain information please provide it'
this obviously isnt enough - would you have any advice on validating numbers to make sure user enters a number
and validating email would be helpful?
Below is what I have done so far - if you do have some idea on how to do the two mentioned above then it would be helpful to show me how to incoporate it into the code - as when I try and incorporate other js with what I already have I find that it gets confusing and doesnt work.
Code: Select all
<SCRIPT LANGUAGE="javascript"> <!-- function focus() { document.formsї0].FirstName.focus(); } function checkme() //check for required fields { if (document.formsї0].firstname.value == "") {alert("You did not enter a first name. Please provide it."); document.formsї0].firstname.focus();return(false) } if (document.formsї0].surname.value == "") {alert("You did not enter a Surname. Please provide it."); document.formsї0].surname.focus();return(false) } if (document.formsї0].organisation.value == "") {alert("You did not enter an Organisation. Please provide it."); document.formsї0].organisation.focus();return(false) } if (document.formsї0].org_id.value == "") {alert("You did not enter an Organisation ID. Please provide it."); document.formsї0].organisation.focus();return(false) } } //--> //--> </SCRIPT> </head> <body onLoad="focus()"> <form method="post" action="processpeople.html" onSubmit="return checkme()" name=Feedback> and then below are all my text boxes
here's a better way to do that:
untested:
Code: Select all
<script>
var msg = "The following information needs attention \n";
with(document.formName){
if(field1.value == ""){
msg += "Field1 can not be left blank \n";
}
if(isNaN(parseInt(field2.value))){
msg += "Field 2 must be a number \n";
}
if(msg.length > (whatever the length of the first one is)){
alert(msg);
return false;
}else{
return true;
}
}field 2 up there is how you check for numbers. To check for valid email address just search the string for a "@" and a "." and maybe make sure there's a domain extension
in the future, it would be wise to keep this stuff in the threads so that others can see the resolutions.
In my opinion validation on the user side is a waste of coding time. You have to validate on the PHP side in case the user has javascript switched off (on purpose perhaps, in order to enter invalid data..) .. so why bother writing two sets of code to do the same thing?
Also, if you validate in JavaScript you're probably giving the user an alert box with their errors in.. that vanishes once they click ok. I prefer to change the form and highlight areas they went wrong*.. Thats considerably more difficult in Javascript.
* Example: http://www.ooer.com/index.php?section=email .. try submitting an empty message.
Also, if you validate in JavaScript you're probably giving the user an alert box with their errors in.. that vanishes once they click ok. I prefer to change the form and highlight areas they went wrong*.. Thats considerably more difficult in Javascript.
* Example: http://www.ooer.com/index.php?section=email .. try submitting an empty message.