Jump to content

DEFINITELY FOR AN EXPERT ANSWER--working with checkboxes


medaswho

Recommended Posts

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?

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 />";
}
?>

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'

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.