Jump to content
Larry Ullman's Book Forums

Checkbox Array In Form Handling – Multiple Checkbox Values In An Array


Recommended Posts

This is something that stumped me right now and i found this webpage with a useful solution. I have an inventory page in which i can select check boxes next to the product listing to end as many products as i like, there could be 10 or 20 products, depending how many the user has added. We can add our checkbox values into an array.



Link to comment
Share on other sites

Just want extend on this topic, we can tidy up our registration form for example by using an array like this







now if we do this we don't have to over populate our global $_POST array, with all this garbage for example







We would only need instead to use $_POST['user'];


This could then be banged into an array as


$user = $_POST['user'];


Then user can be referenced as


$first_name = $user['first_name']

$last_name = $user['last_name'];

$address = $user['address'];

$age = $user['age'];


You don't need to assign array values to separate variables its just to break it up a bit and explain. Well the reason i wanted to add this is because if you have a larger website, you need to really organize exactly what will be saved in your $_POST array so by doing this your code will be more modular.

Link to comment
Share on other sites


  • Create New...