ag3nt42 Posted July 21, 2008 Share Posted July 21, 2008 hello, I have a question how form inputs.. its not php code persay but this seems like the suitable forum to ask the question and I will be using it inside php so.. I kno that on a multiple selection query you can use \[\] at the end of the name and that makes it send the information as an array. Now my question is can you do that same thing with a regular text input? sorta like : <input type='text' name='tall_chicken[]' value='' /> <input type='text' name='tall_chicken[]' value='' /> <input type='text' name='tall_chicken[]' value='' /> <input type='submit' value='Submit' name='action' /> then can you catch it the same way like: <?php if(isset($_POST['tall_chicken'])) { $count=count($_POST['tall_chicken']); for($x=0;$x<=$count;$x++) { $Chicken[$x]=$_POST['tall_chicken'][$x]; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/115871-form-question/ Share on other sites More sharing options...
.josh Posted July 21, 2008 Share Posted July 21, 2008 did you try it? Quote Link to comment https://forums.phpfreaks.com/topic/115871-form-question/#findComment-595735 Share on other sites More sharing options...
ag3nt42 Posted July 21, 2008 Author Share Posted July 21, 2008 i knew somone would say that... lol.. no i didn't.. I didn't want to have to change all of this code around just to try something that might or might not work ya. know. Quote Link to comment https://forums.phpfreaks.com/topic/115871-form-question/#findComment-595749 Share on other sites More sharing options...
.josh Posted July 21, 2008 Share Posted July 21, 2008 well aside from the fact that you don't have form tags, that should work just fine. edit: though, I'd personally use a foreach loop instead of counting and using a for loop. Quote Link to comment https://forums.phpfreaks.com/topic/115871-form-question/#findComment-595765 Share on other sites More sharing options...
.josh Posted July 21, 2008 Share Posted July 21, 2008 Also fyi, the array will always go from 0 to whatever, even if you clicked say, the 2nd and 3rd option, but not the first, the array elements will still be 0-1 not 1-2. Or if you entered in something for #1 and #3 the posted array will still be in positions 0 and 1 not 0 and 2. If for some reason you need to know what position they are in on the form, you need to specify an array position not just do [] in your form. Quote Link to comment https://forums.phpfreaks.com/topic/115871-form-question/#findComment-595773 Share on other sites More sharing options...
ag3nt42 Posted July 21, 2008 Author Share Posted July 21, 2008 Also fyi, the array will always go from 0 to whatever, even if you clicked say, the 2nd and 3rd option, but not the first, the array elements will still be 0-1 not 1-2. Or if you entered in something for #1 and #3 the posted array will still be in positions 0 and 1 not 0 and 2. If for some reason you need to know what position they are in on the form, you need to specify an array position not just do [] in your form. huh Quote Link to comment https://forums.phpfreaks.com/topic/115871-form-question/#findComment-595782 Share on other sites More sharing options...
.josh Posted July 21, 2008 Share Posted July 21, 2008 "huh" as in you don't understand? or "huh" as in "that's interesting" ? Quote Link to comment https://forums.phpfreaks.com/topic/115871-form-question/#findComment-595795 Share on other sites More sharing options...
ag3nt42 Posted July 21, 2008 Author Share Posted July 21, 2008 as in ??? i don't understand what your talking about sry. Quote Link to comment https://forums.phpfreaks.com/topic/115871-form-question/#findComment-595797 Share on other sites More sharing options...
LemonInflux Posted July 21, 2008 Share Posted July 21, 2008 What they mean is, the first value of $array is $array[0], the second is $array[1] etc. etc. Basically, the first is 0, not 1 ---------------- Now playing: Dance Gavin Dance - The Backwards Pumpkin Song via FoxyTunes Quote Link to comment https://forums.phpfreaks.com/topic/115871-form-question/#findComment-595801 Share on other sites More sharing options...
.josh Posted July 21, 2008 Share Posted July 21, 2008 well but I'm also saying that if you have 3 fields and fill out all 3 of them, your posted array positions will be: $_POST['tall_chicken'][0] $_POST['tall_chicken'][1] $_POST['tall_chicken'][2] but if you only put text into say, field 1 and field 3, it will not be positions $_POST['tall_chicken'][0] $_POST['tall_chicken'][2] it will be $_POST['tall_chicken'][0] $_POST['tall_chicken'][1] Quote Link to comment https://forums.phpfreaks.com/topic/115871-form-question/#findComment-595806 Share on other sites More sharing options...
ag3nt42 Posted July 21, 2008 Author Share Posted July 21, 2008 oh well i'm not really worried about the positions of them.. I'm only using them to submit data at this point.. and they will not need to get values placed back into them. thankx tho.. I think I got her working. Quote Link to comment https://forums.phpfreaks.com/topic/115871-form-question/#findComment-595913 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.