Your question, your audience. Choose who sees your identity—and your question—with question security.
<?php // RAY_checkboxes_session.php
error_reporting(E_ALL);
session_start();
// INITIALIZE SOME TEST DATA - THIS MIGHT COME FROM A DATA BASE
if (!isset($_SESSION['box1'])) $_SESSION['box1'] = FALSE;
if (!isset($_SESSION['box2'])) $_SESSION['box2'] = FALSE;
if (!isset($_SESSION['box3'])) $_SESSION['box3'] = FALSE;
// PROCESS THE POST DATA
if ( isset($_GET['box1'])) $_SESSION['box1'] = TRUE;
if ( isset($_GET['box2'])) $_SESSION['box2'] = TRUE;
if ( isset($_GET['box3'])) $_SESSION['box3'] = TRUE;
if (!isset($_GET['box1'])) $_SESSION['box1'] = FALSE;
if (!isset($_GET['box2'])) $_SESSION['box2'] = FALSE;
if (!isset($_GET['box3'])) $_SESSION['box3'] = FALSE;
// TELL WHAT WAS CHECKED
if ($_SESSION['box1']) echo 'YOU CHECKED box1<br/>';
if ($_SESSION['box2']) echo 'YOU CHECKED box2<br/>';
if ($_SESSION['box3']) echo 'YOU CHECKED box3<br/>';
// CREATE THE FORM
$form = <<<EOFORM
<form method="get">
CHECK OR UNCHECK SOME BOXES HERE<br/>
<input name=box1 type="checkbox" /><br/>
<input name=box2 type="checkbox" /><br/>
<input name=box3 type="checkbox" /><br/>
<input type="submit" value="go" />
</form>
EOFORM;
// REPLACE THE FORM FIELDS TO INDICATE THE CHECKED VALUES IN THE SESSION
if ($_SESSION['box1']) $form = str_replace('box1', 'box1 checked', $form);
if ($_SESSION['box2']) $form = str_replace('box2', 'box2 checked', $form);
if ($_SESSION['box3']) $form = str_replace('box3', 'box3 checked', $form);
// PRESENT THE FORM
echo $form;
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
Copy the checkbox information into the $_SESSION array and recover the checkbox information from the $_SESSION array.
As you do this, be aware that unchecked checkboxes do not appear in the request at all - they are not present and empty like an empty text input control; they are simply missing from the request.
Does that help answer the question?