select multiple options
html, php
Solution
Put [] after the name:
<input type="checkbox" name="test[]" value="Newspaper">
See PHP FAQ for more details.
Problem
banging my head against the wall for something seemingly dead simple. Here it is: ``` <html> <head></head> <body> <form method="post" action="action.php"> <div><input type="checkbox" name="test" value="Newspaper"> <span >Newspaper</span></div> <div><input type="checkbox" name="test" value="PC"> <span >PC</span></div> <div><input type="checkbox" name="test" value="Home"> <span >Home</span></div> <div><input type="checkbox" name="test" value="Dont_know"> <span >dnunno</span></div> <input type="submit" name="Submit" value="send"> </form> </body> </html> ``` But when I select more then one option. I see in my `print_r($_POST);` statement only the last selected option in stead of all selected options. How should I deal with this? update: I checked the rest of my code and i saw that this is done by some JavaScript. ``` else if (aform.validatorArr[i][4] == "checkbox") { var fvs = ""; eval("var chkbArray=aform." + aform.validatorArr[i][1] + ";"); if (aform.validatorArr[i][2] == "cb_true") { for (k = 0; k < chkbArray.length; k++) { if (chkbArray[k].checked) { fvs += chkbArray[k].value; console.log(fvs); } } if (fvs == false) { s += aform.validatorArr[i][3] + "\n"; } } } ``` That's why the [] is not added in my html. But how could I modify this code so that it will take all options?