[thelist] checked vs. unchecked checkboxes

Robert Vreeland vreeland at studioframework.com
Tue Oct 19 23:22:02 CDT 2004


You can also set up your input fields as an array that PHP can process. In
doing so, the form will correctly post back only those items checked.
Example below:
<html>
<body>
<?PHP
if(isset($_POST["formdata"])){
 $array = $_POST["formdata"];
 for($i = 0; $i < count($array); $i++){
  echo $array[$i] . "<br>";
 }
}
?>
<form method="post" action="test.php">
option one<input type="checkbox" name="formdata[]" value="one"><br>
option two<input type="checkbox" name="formdata[]" value="two"><br>
option three<input type="checkbox" name="formdata[]" value="three"><br>
option four<input type="checkbox" name="formdata[]" value="four"><br>
<input type="submit">
<input type="reset">
</form>
</body>

Robert Vreeland
Managing Partner
StudioFramework
vreeland at studioframework.com
----- Original Message ----- 
From: "noah" <noah at tookish.net>
To: <thelist at lists.evolt.org>
Sent: Tuesday, October 19, 2004 8:52 PM
Subject: Re: [thelist] checked vs. unchecked checkboxes


> Gary McPherson wrote (19/10/2004 7:56 PM):
>
> > I think the simplest way to handle this would be to process all
available
> > options each time that form is submitted.
>
> If it's feasible, I think that Gary's is the best solution.
>
> If you really want to compare the new options to the existing ones, you
> will either have to pull the existing options from the DB when you
> process the form, or you'll have to put the existing options in a hidden
> field in the form itself, then turn it into an array and compare the two
> arrays (the existing options vs. the new options) when the form is
> processed.
>
> Cheers,
> Noah
> -- 
>
> * * Please support the community that supports you.  * *
> http://evolt.org/help_support_evolt/
>
> For unsubscribe and other options, including the Tip Harvester
> and archives of thelist go to: http://lists.evolt.org
> Workers of the Web, evolt !



More information about the thelist mailing list