hi all,
I want to validate the form data with Javascript and then pass the form to PHP server to put the data into the database. Things get complicated because I have
more than 30 checkboxes on this form, each having different values. I have tried two approaches and both are not working the way I want to.
- <input type="checkbox" name="interests[]" value="28" >
In this case PHP parses the array of checkboxes and inserts them correctly in the database with the following code:
for($i=0;$i < $nr_of_checked; $i++){
mysql_query = INSERT ($interests[$i];
}
However Javascript gives me an error and does not enable to check whether any of the checkboxes is checked, as it requires the form to be written in the following way, i.e without array brackets in HTML code:
<input type="checkbox" name="interests" value="28" >
2.So, if I write the form like this, then Javascript checks whether the user has checked any of the checkboxes, but php of course does not recognize the checkbox variable as an array anymore and inserts only the last checked.
There is of course a dumb way to solve this problem, which would be to have different variable for each of the checkboxes. As this makes the code more than kilometer long, I am not too keen to do this. I have read the manuals and forums, but have not noticed this type of problem anywhere. Any help is appreciated.
Seibs