giraffemedia Posted January 19, 2011 Share Posted January 19, 2011 Hi I have a form populated with an array of checkboxes (with labels). When I submit the form to the same page none of the checkbox values are remembered. What is the best way of achieving this? If I echo the checked box values it tells me which ones were selected but I cannot get the actual boxes to remember if they were checked or not. Here is what I have… $checked = $_POST['issue']; foreach($checked as $item) { echo "Item $item was checked<br />"; } while ($row = mysql_fetch_array($issue_query)) { $issues[] = '<span style="display:block;margin:0px 0px 10px 60px;"><input name="issue[]" type="checkbox" style="width:auto;" value="'.$row['issue_number'].'">Issue <strong>'.$row['issue_number'].'</strong> '.$row['issue_month'].' '.$row['issue_year'].'<span>'; } Any ideas? Thanks, James Quote Link to comment Share on other sites More sharing options...
Porl123 Posted January 19, 2011 Share Posted January 19, 2011 $checked = $_POST['issue']; foreach($checked as $item) { echo "Item $item was checked<br />"; } while ($row = mysql_fetch_array($issue_query)) { $issues[] = '<span style="display:block;margin:0px 0px 10px 60px;"><input name="issue[]" type="checkbox" style="width:auto;" value="'.$row['issue_number'].'"'.(in_array($row['issue_number'],$_POST['issue']) ? ' checked="checked"' : '').'>Issue <strong>'.$row['issue_number'].'</strong> '.$row['issue_month'].' '.$row['issue_year'].'<span>'; } You could try that. I'm not 100% sure, though. D: Quote Link to comment Share on other sites More sharing options...
giraffemedia Posted January 20, 2011 Author Share Posted January 20, 2011 Works like a charm Porl123! I had to add an if isset statement around the whole script to stop it giving me errors if the array was empty but apart from that great. Thanks, James Quote Link to comment 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.