RE: [PHP-DB] Re: Need help with delete and modify functions on a form.
| From: | Norland, Martin | Date: | Tue, 18 Oct 2005 13:31:39 +0000 |
| Subject: | RE: [PHP-DB] Re: Need help with delete and modify functions on a form. | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-40525@lists.php.net to get a copy of this message | ||
>-----Original Message-----
>From: Arie Nugraha [mailto:dicarve@gmail.com]
>
>You can also use an array :
>
><form>
><input type="checkbox" name="check[]"
>value="someValue1"> Some
Value 1
><input type="checkbox" name="check[]"
>value="someValue2"> Some
Value 2
><input type="checkbox" name="check[]"
>value="someValue3"> Some
Value 3
></form>
>
>to get the the third value from the form you can do like this :
>
><?php
>echo $_POST["check"][2];
>?>
Good basic examples, two notes though -
1) <form method="post"> (blindingly obvious to most, but might confuse
some)
2) the name/value pair will only be POSTed if it's checked, so that
would only work if the first two were checked.
Some people like to pair all their checkboxes with a hidden of the same
name, the hiddens value will be sent if the checkbox isn't checked.
Personally, I prefer having an actual unique name for the checkbox when
you need to check a specific one. If you don't need to check if 'the
third one' is set, but you're just getting - for e.g. - a list of pizza
toppings, then the order doesn't matter and [] works fine. Otherwise
(if it does), give it a unique name:
<input type="checkbox" name="check[0]"
value="someValue1"> Some
Value 1
<input type="checkbox" name="check[1]"
value="someValue2"> Some
Value 2
<input type="checkbox" name="check[2]"
value="someValue3"> Some
Value 3
(although a little more unique would be clearer :) )
cheers,
- Martin Norland, Sys Admin / Database / Web Developer, International
Outreach x3257
The opinion(s) contained within this email do not necessarily represent
those of St. Jude Children's Research Hospital.