Jump to content

Checkboxes ...


techiefreak05

Recommended Posts

the net is always useful where most programming is concerned, you just need to know what you're looking for.  you need to know two things; first, how checkboxes work, and second, how to process arrays.  checkboxes will only send values if they are checked.  if they are unchecked, no variable will even be initialized in the $_POST array.  second, you can name any HTML input as an array, resulting in its value being placed into the relevant sub-array item created in $_POST.  that being said, you can do something like this:

 

ID 1 <input type="checkbox" name="ids_checked[]" value="1" />
ID 2 <input type="checkbox" name="ids_checked[]" value="2" />
ID 3 <input type="checkbox" name="ids_checked[]" value="3" />

 

and in the PHP processing the form input, process through the $_POST['ids_checked'] array:

 

foreach ($_POST['ids_checked'] AS $this_id)
{
  $query = SOME QUERY USING $this_id;
}

 

i'm sure you can expand from there.  if you need to relate that checkbox to a certain set of information (like a row, for example), then use its ID as the index in the other information, and name that as an array:

 

<input type="text" name="title[this_rows_id]" value="some title" />

 

give it a whirl.

Link to comment
https://forums.phpfreaks.com/topic/55301-checkboxes/#findComment-273365
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.