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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.