note 50989 deleted from language.variables.external by danbrown

From: Date: Wed, 09 Mar 2011 14:39:48 +0000
Subject: note 50989 deleted from language.variables.external by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-177704@lists.php.net to get a copy of this message
Note Submitter: agup at cpr dot org ---- If you have multiple checkboxes that you want to submit from an html form to process elsewhere, you might try using this methodology: 1) create a unique id number for each row in the table 2) assign that unique row id to each checkbox input name 3) pass the total number of rows as a hidden value in the form 4) recover all the checkbox booleans by iterating through all the unique settings. 5) on the downstream page you can assign any value you want to the variable before writing it to the database or whatever you need to do. For example; you can assign the value 0 if the boolean for the checkbox is FALSE. row=0; do{ <form name="some_name" action="some_action.php" method="post"> <td><input type="checkbox" name="unique_item[<?echo$row?>]"> <INPUT TYPE="hidden" name="row_count" value="<?echo$row?>"></INPUT> <INPUT TYPE="submit" name="...."> . . row++; } while (something); </table> </form> Upon submit, all the unique checkbox booleans can then be recovered on another PHP page using: $some_data = $_POST['some_data']; $row_count = $_POST['row_count']; $row=0; do { if($some_data[$row]){ ...do something...e.g. assign a variable, write to db, etc. } if(!$some_data[$row]){ ...do something...e.g. assign a variable, write to db, etc. } $row++; } while ($row<$row_count); I left out alot of syntax since this example is simply illustrative to cover multiple scenarios. Don't forget to always validate form data before entering it into a database. I hope this helps.

« previous php.notes (#177704) next »