Jump to content

Checkbox Form


TheFilmGod

Recommended Posts

<input type="checkbox" name="activity[]" value="brunch" />
		<br />Dance
	<input type="checkbox" name="activity[]" value="dance" />
		<br />Game
  		<input type="checkbox" name="activity[]" value="game" />

 

I would like to extract the submitted info. Since the checkboxes are already in an array how can I use php to simple do this:

 

If checked $element = 1

 

if not checked $element = 0 ?

 

I'm new to php and forms, and I finally stopped copying and pasting and started writing my scripts but as you see, that is HARD!! LOL.  >:(

Link to comment
https://forums.phpfreaks.com/topic/66695-checkbox-form/
Share on other sites

you can, but it will only give you the second item in the array. You will lose the rest of the checked items

 

Anytime your dealing with an array, you will have to do a loop to extract all the results. If you know there are only going to be X number of items, then you can address them using the $_POST['activity'][X], but that can get tedious if there are more than a few items.

 

Loops are your friend :)

Link to comment
https://forums.phpfreaks.com/topic/66695-checkbox-form/#findComment-334301
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.