Okay, on a form I have a number of select inputs:
Tag_1
Tag_2
Tag_3
The problem is the user can increase and decrease the number of inputs at will.
I am recording the number of Tag inputs and this is passed as a hidden variable, but how do I allow for this when the form is passed on and I need to draw a table with the selected Tag as headers?
I know that $_POST['Tag_1'] is valid, but is $_POST['Tag_'. $i] ? Is that a valid array index?
Cheers,
HKHorus,
I'm sure what your planning to do should work...altho...you could try this:
$c = $_POST["count"]; //number of fields..hidden value
for($x = 0;$x > $c;$x++)
{
$key = 'tag_'.$x;
echo $_POST[$key];
}
just a thought....you could always use array_push or such if you need to fill another array.yeah, thanks Willamoose.or you could make $_POST['Tag_1'] an array
$_POST['Tag_1'][$i]so $_POST['Tag_1'][1] is the same as $_POST['Tag_2'] - that doesn't sound right to me...and you are correct, it isn't the same. I was just mentioning that you don't have to change the name when you could just use array's. makes life so much easieryou can post arrays from a form?yes
<input type='hidden' name='tag[]' value='value'>
will end up being
$_POST['tag'][$i]
so much easier then to change the name. you still have to loop with something like what Will said.
Tag_1
Tag_2
Tag_3
The problem is the user can increase and decrease the number of inputs at will.
I am recording the number of Tag inputs and this is passed as a hidden variable, but how do I allow for this when the form is passed on and I need to draw a table with the selected Tag as headers?
I know that $_POST['Tag_1'] is valid, but is $_POST['Tag_'. $i] ? Is that a valid array index?
Cheers,
HKHorus,
I'm sure what your planning to do should work...altho...you could try this:
$c = $_POST["count"]; //number of fields..hidden value
for($x = 0;$x > $c;$x++)
{
$key = 'tag_'.$x;
echo $_POST[$key];
}
just a thought....you could always use array_push or such if you need to fill another array.yeah, thanks Willamoose.or you could make $_POST['Tag_1'] an array
$_POST['Tag_1'][$i]so $_POST['Tag_1'][1] is the same as $_POST['Tag_2'] - that doesn't sound right to me...and you are correct, it isn't the same. I was just mentioning that you don't have to change the name when you could just use array's. makes life so much easieryou can post arrays from a form?yes
<input type='hidden' name='tag[]' value='value'>
will end up being
$_POST['tag'][$i]
so much easier then to change the name. you still have to loop with something like what Will said.