Having a form, where the variables are elements of an array.

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
Age of Fable
Posts: 54
Joined: Fri Feb 19, 2010 6:37 am

Having a form, where the variables are elements of an array.

Post 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)?
Easy to play - hard to survive. http://www.ageoffable.net
User avatar
Torniquet
Posts: 869
Joined: Sun Aug 02, 2009 6:18 am

Re: Having a form, where the variables are elements of an array.

Post 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
New Site Coming Soon! Stay tuned :D
Xaleph
Posts: 897
Joined: Mon Feb 07, 2011 2:55 am

Re: Having a form, where the variables are elements of an array.

Post by Xaleph »

read below.misread.
Last edited by Xaleph on Sat Jul 30, 2011 4:05 pm, edited 1 time in total.
Xaleph
Posts: 897
Joined: Mon Feb 07, 2011 2:55 am

Re: Having a form, where the variables are elements of an array.

Post 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
}
Post Reply

Return to “Beginner Help and Support”