Re: checkbox validation

From: Date: Wed, 18 Apr 2001 09:54:07 +0000
Subject: Re: checkbox validation
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-49168@lists.php.net to get a copy of this message
Jacky wrote: > > Hi all > I have a form with the checkbox like this > <form> > $query="select id from foo"; > $result=($query,$con); > while ($row = mysql_fetch_array($result)) > { > <input type="checkbox" name="$id" value="on"> > } > ....submit button and stuffs here... > </form> One possibility: Add a hidden field in the form and write all names of the checkboxes in it, separated by a semicolon, for example. ----------------------------------------------------------------------------- <form> $query="select id from foo"; $result=($query,$con); while ($row = mysql_fetch_array($result)) { <input type="checkbox" name="$id" value="on"> $names_of_checkboxes.=$id.";"; } <input type="hidden" name="names_of_checkboxes" value="<? echo $names_of_checkboxes; ?>"> ....submit button and stuffs here... </form> ------------------------------------------------------------------------------- Then, in the next page you just do following: --------------------------------------------------------------------------- $checkboxes_names_array=explode(";",$names_of_checkboxes); for($x=0;x<count($checkboxes_names_array);$x++) { if($$checkboxes_names_array[$x]=="on") // box checked } ------------------------------------------------------------------------------- Robert

« previous php.general (#49168) next »