[thelist] newbie: why <input name="something[]" ... /> ?

Brian Cummiskey Brian at hondaswap.com
Wed Aug 24 22:11:19 CDT 2005


Zhang Weiwu wrote:

>Why I see a lot of people adding an empty [] after the variable name
>used in <input> ? Is there a good reason?
>
>  
>
the brackets denote an array.  The most common useage is when you have a 
<select name="field1[]" multiple="multiple"> box, where a user can 
control-click more than one option.
on the processing page, you can loop through and grab all the selected 
options in a loop.

useage on an input field is less common, and frankly, i don't see the 
point, as only one value is being passed.
Unless, you have multiple inputs with the same name...  perhaps, an 
upload form with <input type="file" name="uplodedfile"/> and again, 
<input type="file" name="uplodedfile"/> and then, on the process page, 
loop through for each $_POST['uploadedfile'] .... etc

HTH


More information about the thelist mailing list