medaswho Posted February 24, 2009 Share Posted February 24, 2009 I am building an options wizard. the options are dynamic and come from the db and are added to the first page in the form of a variable and a check box with the variable's name. once the page is complete, the end user can select any of several options and then submit the form on to the next page. my dilemma is i know how to get the number of check boxes checked, but how do i get the number AND name of checkboxes? Link to comment https://forums.phpfreaks.com/topic/146682-definitely-for-an-expert-answer-working-with-checkboxes/ Share on other sites More sharing options...
rhodesa Posted February 24, 2009 Share Posted February 24, 2009 well, what does your form look like? i recommend like this: <input type="checkbox" name="option[opt1]" /> Option 1<br /> <input type="checkbox" name="option[opt2]" /> Option 2<br /> <input type="checkbox" name="option[opt3]" /> Option 3<br /> then the script you post to: <?php foreach(array_keys($_POST['option']) as $key){ echo "Option '$key' was checked<br />"; } ?> Link to comment https://forums.phpfreaks.com/topic/146682-definitely-for-an-expert-answer-working-with-checkboxes/#findComment-770106 Share on other sites More sharing options...
medaswho Posted February 24, 2009 Author Share Posted February 24, 2009 that's good. that's very good! that's more simple then what i was going to try. i was going to try(and still might) tampering with the var_export() function but the simpler the better... foreach might indeed be the way to go. Link to comment https://forums.phpfreaks.com/topic/146682-definitely-for-an-expert-answer-working-with-checkboxes/#findComment-770115 Share on other sites More sharing options...
rhodesa Posted February 24, 2009 Share Posted February 24, 2009 What would you do with var_export() ??? Link to comment https://forums.phpfreaks.com/topic/146682-definitely-for-an-expert-answer-working-with-checkboxes/#findComment-770119 Share on other sites More sharing options...
medaswho Posted February 24, 2009 Author Share Posted February 24, 2009 var_export() outputs a string. i need to know the name of the checkbox that is selected. as the data comes from the db, it get's displayed in this manner: <input type='checkbox' name=' ".$variable." '> ".$variable i would use a foreach to tell me how many checkboxes had been selected but i hadn't considered i could use a foreach to get the 'name' Link to comment https://forums.phpfreaks.com/topic/146682-definitely-for-an-expert-answer-working-with-checkboxes/#findComment-770139 Share on other sites More sharing options...
rhodesa Posted February 24, 2009 Share Posted February 24, 2009 yeah, the foreach is way better. you could keep your format and use foreach(array_keys($_POST) as $key){ but my way of doing the inputs allows for other form elements without affecting the PHP Link to comment https://forums.phpfreaks.com/topic/146682-definitely-for-an-expert-answer-working-with-checkboxes/#findComment-770151 Share on other sites More sharing options...
medaswho Posted February 24, 2009 Author Share Posted February 24, 2009 i agree. thanks again. Link to comment https://forums.phpfreaks.com/topic/146682-definitely-for-an-expert-answer-working-with-checkboxes/#findComment-770245 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.