/    Sign up×
Community /Pin to ProfileBookmark

return unchecked checkboxes

Hi, what options do I have for getting my form handler to return the values of checkboxes that are not checked rather than those that are? What would be the simplest option? I can imagine setting it up to include a ‘hidden’ array that holds all the line items, and then using array_diff to compare it to those line items that the user checks off to get rid of. But this approach doesn’t work in my larger code scheme. Any suggestions for other options?

<html><body>
<form name=”myName” form method=”POST” action=”checkbox.php”>
<input type=”submit” value=”Remove”>
<br />
<?php
//while ($line1 = mysql_fetch_array($myArray, MYSQL_ASSOC)){

//Data actually comes from a mysql query
$myArray=array(cat,dog,horse,bird,cow,mouse,pony,rat,bug,bat);
foreach ($myArray as $value) {
?>
<input type=’checkbox’ name= ‘checkNum[]’ value='<?php echo($value);?>’>
<?php
print_r($value);
?>
<br />
<?php
}
//}
?>
</form></body></html>
<html>
<body>
<!–So…if the first three elements are checked….–>

File name=checkbox.php
<?php
$checked=$_POST[‘checkNum’];
$imploded= implode(“…”, $checked);

//what I don’t want is this printout
echo “<br><br>$imploded”; //prints cat…dog…horse

//what I do want is this printout”;
echo “<br><br>bird…cow…mouse…pony…rat…bug…bat”;
?>
</body>
</html>

Thanks!

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@NogDogApr 11.2006 — You could have the form-handler run the same query that you used to populate the checkboxes, then walk through the results to see which have matching keys in the $_POST data and which do not.
×

Success!

Help @tonyB spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...