TheFilmGod Posted August 25, 2007 Share Posted August 25, 2007 <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. Quote Link to comment https://forums.phpfreaks.com/topic/66695-checkbox-form/ Share on other sites More sharing options...
Barand Posted August 25, 2007 Share Posted August 25, 2007 Only checked values will be posted. <?php foreach ($_POST['activity'] as $act) { // process activity echo $act } Quote Link to comment https://forums.phpfreaks.com/topic/66695-checkbox-form/#findComment-334143 Share on other sites More sharing options...
TheFilmGod Posted August 26, 2007 Author Share Posted August 26, 2007 Is there a way I can simple do this: $_POST['activity][1]? Quote Link to comment https://forums.phpfreaks.com/topic/66695-checkbox-form/#findComment-334272 Share on other sites More sharing options...
chronister Posted August 26, 2007 Share Posted August 26, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/66695-checkbox-form/#findComment-334301 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.