Page 1 of 1
Having a form, where the variables are elements of an array.
Posted: Sat Jul 30, 2011 11:16 am
by Age of Fable
I want to have a series of drop-down menus, where the first drop-down menu selects $card[1], the second selects $card[2], and so on.
Does anyone know how to do this (with php if necessary)?
Re: Having a form, where the variables are elements of an array.
Posted: Sat Jul 30, 2011 12:38 pm
by Torniquet
never done this with dropdowns, but at a guess label each select tag with the representing name..
<select name="card[1]">
</select>
<select name="card[2]">
</select>
etc...
then through php
$cards = $_POST['card'];
$card1 = $cards[1];
$card2 = $cards[2];
etc...
this is best guess in this scenario, but logic dictates it should work lol
Re: Having a form, where the variables are elements of an array.
Posted: Sat Jul 30, 2011 4:02 pm
by Xaleph
read below.misread.
Re: Having a form, where the variables are elements of an array.
Posted: Sat Jul 30, 2011 4:05 pm
by Xaleph
Oh wait, i misread.
You can use the name attribute on selects.
Just use a global name for each select and add a number to it. Like
<select name="cards-1">
<select name="cards-2">
<select name="cards-3">
Now, in PHP you can use substring to get the number back.
$number = substr($post, 0,6);
if($number == 'cards-'){
$number = substr($post, 6); // is 1 or 2 or 3
}