Jump to content

form question..


ag3nt42

Recommended Posts

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];
}
}

?>

 

Link to comment
https://forums.phpfreaks.com/topic/115871-form-question/
Share on other sites

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. 

Link to comment
https://forums.phpfreaks.com/topic/115871-form-question/#findComment-595773
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/115871-form-question/#findComment-595782
Share on other sites

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]

 

Link to comment
https://forums.phpfreaks.com/topic/115871-form-question/#findComment-595806
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.