List element in a Form

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Zoram
Forum Contributor
Posts: 166
Joined: Sun Aug 18, 2002 3:28 pm
Location: Utah
Contact:

List element in a Form

Post by Zoram »

I am trying to get a List to work so that the user can select several of the options and it saves that as the field... anyway, here is what i got.

Code: Select all

<select name="sizes" size="3" multiple id="sizes">
          <option value="XS">XS</option>
          <option value="S">S</option>
          <option value="M">M</option>
          <option value="L">L</option>
          <option value="XL">XL</option>
          <option value="XXL">XXL</option>
          <option value="XXXL">XXXL</option>
        </select>
How would i make it so that it stores all the options selected in the following format?

Code: Select all

(say i selected : S, M, XXL)
$sizes = S, M, XXL;
Thanks!
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

Code: Select all

$picked = "";
foreach($sizes as $value){
$picked .= " ".$value.",";
}
$picked = trim($picked, ",");
try something like that...
User avatar
Zoram
Forum Contributor
Posts: 166
Joined: Sun Aug 18, 2002 3:28 pm
Location: Utah
Contact:

Post by Zoram »

would that be on the page that i insert it into the table?
User avatar
mr_griff
Forum Commoner
Posts: 64
Joined: Tue Sep 17, 2002 11:11 am
Location: Bozeman, Montana

Post by mr_griff »

You will also need to change the name attribute in your select tag be sizes[] (<- note the square brackets) so that it will be an array after the form is submitted. Then use the code hob_goblin posted.
User avatar
Zoram
Forum Contributor
Posts: 166
Joined: Sun Aug 18, 2002 3:28 pm
Location: Utah
Contact:

Post by Zoram »

alright, that works but it didn't trim that last ,
User avatar
mr_griff
Forum Commoner
Posts: 64
Joined: Tue Sep 17, 2002 11:11 am
Location: Bozeman, Montana

Post by mr_griff »

Post Reply