I spend about 50% of my time developing for ASP on IIS. One common method I use in ASP programming is to give multiple form elements the same name. For instance, I might have a form like this:
<form>
Please select your favorite languages<br>
<input type=checkbox name=fav_lang value=ASP>ASP<br>
<input type=checkbox name=fav_lang value=PERL>PERL<br>
<input type=checkbox name=fav_lang value=PHP>PHP<br>
<br><br>
Enter any other languages:<br>
<input type=text name=other_lang><br>
<input type=text name=other_lang><br>
<input type=submit>
</form>
The form would then return a comma delimited list of the values that were checked or entered. In the example above, had the user checked items 1 & 3 and filled out both text boxes my return values would be like this:
response.write request.form("fav_lang") 'prints "ASP, PHP"
response.write request.form("other_lang") 'prints "value1, value2"
I've tried to mirror this functionality in PHP on Apache but the return value is only a single (either the first or the last item, I can't remember) value. I thought it might be putting the items into an array but using print_r() on the returned value doesn't specify that it is an array.
My question is whether this is a result of how Apache processes a form or how PHP stores same-name form elements. Does anyone know if there is a way to mimic the functionality of this method on ASP/IIS?
The alternative, at least the one that I've resorted to works, but is pretty lengthy:
<?php
$num_of_fields = 12; //total number of same-name fields to check
for($iField = 1;$iField <= $num_of_fields;$iField++){
//set element numbers
$iFmt = "";
if($iField < 10) {
$iFmt = "0" . $iField; //add a leading zero
}else{
$iFmt = $iField;
}
eval("\$outPut = \$field_" . $iFmt . ";");
print "field_" . $iFmt . " = " . $outPut . "<br>";
}
?>
Regards,
Chris