How To Distinguish Between Two Multiple Selection Lists With Same Name
For a system I'm building I need to see which options came in (with POST request) from the first list and which options came in from the second list.
Solution 1:
Divide the categories by creating a multidimensional array in the form:
<formmethod="post"><selectname="cars[0][]"multiple><optionselected>test</option><optionselected>test2</option><option>test3</option><option>test4</option></select><selectname="cars[1][]"multiple><option>hai</option><option>hai2</option><optionselected>hai3</option><optionselected>hai4</option></select><inputtype="submit"></form>
And then reading it like this: $_POST['cars'][0] for the first set and $_POST['cars'][1] for the second
Solution 2:
You should be able to retrieve them like this:
$_POST['cars'][0]
refers to the "test" set
$_POST['cars'][1]
refers to the "hai" set
Solution 3:
I made this:
<?phpif (isset($_POST['cars']))
{
$test = array();
$hai = array();
$lista = $_POST['cars'];
foreach ($listaas$key ) {
if (substr($key,0,1)=="t")
{
$test[] = $key;
}
else
{
$hai[] = $key;
}
}
}
var_dump($test);
var_dump($hai);
?><formmethod="post"><selectname="cars[]"multiple><optionselected>test</option><optionselected>test2</option><option>test3</option><option>test4</option></select><selectname="cars[]"multiple><option>hai</option><option>hai2</option><optionselected>hai3</option><optionselected>hai4</option></select><inputtype="submit"></form>
Tested on localhost.
Saludos :)
Post a Comment for "How To Distinguish Between Two Multiple Selection Lists With Same Name"