Am working on a beginners project and I have problems with my checkboxes. These checkboxes are an array and I need to validate them.
- Students are supposed to choose 2 courses per week.
- However Financial Management is taught for a whole week hence if a student chooses this course in week 1, they are NOT allowed to choose another course in that particular week.
- If a student chooses Financial Management in week 1, they MUST choose it again in week 2.
How do I validate these?
_________________________
The code for the table looks like:
I think you can do this with javascript.By clicking on a button, you can check value of the check box for FM course, then uncheck all other checkbox in week1 and week2, and set the check box for FM in week2.
If FM course is not selected in week1 then just count the number of check box that is set, alert the user with appropriate message.If no error found then submit the form.I can code this idea, but I prefer to but different name for differrent checkbox so that I can access them easily with javascript.
I'm a beginner, dont know much, sorry.
if($maxweek1 == 1 && $week1chosen > 1){
echo "You chose Financial Management in week 1, because of this you can only chose 1 course for week 1<br />";
exit();
}else{
echo "Week 1 is fine!<br>";
}
if($maxweek2 == 1 && $week2chosen > 1){
echo "You chose Financial Management in week 2, because of this you can only chose 1 course for week 2<br>";
exit();
}else{
echo "Week 2 is fine!<br />";
}
?>
Did it in PHP instead of javascript, javascript can be edited by the user so is less secure
Last edited by goughy000; 02-18-2006 at 04:10 PM..
oh, really?user can modify javascript validation functions?I wrote 12 validation function in PHP and then convert all of them to javascript ! it's not good ? I deleted all my PHP functions.But clientside checking is more convenient to user, is it?
You can add client side validation via Javascript for quick interaction with the user (such as alerting them that a required field is not filled in), but you should still have server side validation in place. There have been cases which I've read about where online stores only had client side validation and ended up selling high priced items for $1. Also, don't forget that some people don't have Javascript enabled, so even if they aren't trying to hack it, the validation won't be there for them.
Of course.. they can save the file to there computer, change anything javascript, and load it up again
Quote:
but you should still have server side validation in place
Yes, I agree. As many validation proccesses as possible in place. And after data has been received its always best to check it by hand. But if you have lots of data received daily... ergh
Well, I got your idea, I change PHP to Javascript because I thought it will give some boost in performance, server will be free from validating, but I will think well next time, thanks.