Re: Need some advice concerning forms (multi select pulldown) and arrays

From: Date: Sat, 25 May 2002 18:59:09 +0000
Subject: Re: Need some advice concerning forms (multi select pulldown) and arrays
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-99252@lists.php.net to get a copy of this message
On Sat, 25 May 2002, Victor Spång Arthursson wrote: > I know it's possible to use arrays in combination with forms, but I need > some advice about where to find some information/tutorial concerning how > to use arrays together with "multi-select-tags"... Have a play with this little program - it should demonstrate all of the things you'd want to do with getting data in and out of mult selects. If it doesn't work, you may have an older version of PHP - in that case, change "$_REQUEST" to "$HTTP_POST_VARS" and "$_SERVER['PHP_SELF']" to "$PHP_SELF". --------------- <? $choices = array(1 => 'dog', 2 => 'cat', 3 => 'mouse', 4 => 'frog'); if (is_array($_REQUEST['animals'])) { print '<p>You chose:</p><ul>'; foreach ($_REQUEST['animals'] as $animal_id) print "<li>{$choices[$animal_id]}</li>"; print '</ul><hr>'; } ?><form method="post" action="<?= $_SERVER['PHP_SELF'] ?>"> <select multiple name="animals[]"><? foreach ($choices as $id => $name) print '<option ' . (in_array($id, $_REQUEST['animals']) ? 'selected ' : '') . "value='$id'>$name</option>"; ?></select><input type="submit"></form> --------------- miguel

« previous php.general (#99252) next »