note 50989 added to language.variables.external
| From: | agup at cpr dot org | Date: | Wed, 16 Mar 2005 01:43:44 +0000 |
| Subject: | note 50989 added to language.variables.external | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-86517@lists.php.net to get a copy of this message | ||
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.
----
Manual Page -- http://www.php.net/manual/en/language.variables.external.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+50989
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+50989&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+50989&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+50989&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+50989&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+50989&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+50989&report=yes
Search -- http://master.php.net/manage/user-notes.php