RE: [PHP-DB] multiple checkbox selection for search form
| From: | John W. Holmes | Date: | Wed, 19 Feb 2003 13:07:33 +0000 |
| Subject: | RE: [PHP-DB] multiple checkbox selection for search form | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-25761@lists.php.net to get a copy of this message | ||
> I need some assistance here...
> I am toying with a search form that will allow the user to select 3
> options from a set of checkboxes to search by (eg.)
>
> [[ Select any 3 type ]]
>
> [ ] option1 [ ] option2 [ ] option3
> [ ] option4 [ ] option5 [ ] option6
> [ ] option7 [ ] option8 [ ] option9
>
> what I would like to do is to allow then to select only 3 options
> then search the database for the 3 options selected.
Name all of your checkboxes the same, with an [] on it.
<input type="checkbox" name="option[]" value="option1"> Option1
<input type="checkbox" name="option[]" value="option2"> Option2
etc...
Then, you'll have a $_POST['option'] array (or $_GET) when your form is
submitted.
if(isset($_POST['option']) && count($_POST['option']) <= 3)
{ //perform your search }
else
{ echo "You must select between 1 and 3 options."; }
---John W. Holmes...
PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/