krisjohnson
08-27-2009, 10:52 PM
I'm trying to take the input from a <SELECT> Form item that has the MULTIPLE option turned on.
Once I can do this properly - I plan to populate that list with databse values - but I need to be able to process the users selections in the resulting page call.
print("<select name=subcategory[] multiple=multiple >");
I have a simple list of items and I want the user to be able to select more than one item.
I created my FORM variable as an array - so that the $_POST would process this as an array. I know the $_POST item can return an array - but how do you access that information on the other side?
All examples that I seen really do not address how to move the FORM variable back into a PHP array that can be used.
Basic FORM item:
<?php
print("<form action=./chk_value.php method=post name=newitem>");
print("<fieldset>");
print("<legend class=formTitle> Select A Value </legend>");
print("<P class=ptight>");
print("<label for=subcategory>Product Subcategory</label>");
print("<select name=subcategory[] multiple=multiple >");
print("<option value=1>Apple</option>");
print("<option value=2>Apricots</option>");
print("<option value=3>Bananna</option>");
print("<option value=4>Blueberry</option>");
print("<option value=5>Cherry</option>");
print("<option value=6>Cranberry</option>");
print("<option value=7>Figs</option>");
print("<option value=8>Grapes</option>");
print("<option value=9>Oranges</option>");
print("<option value=10>Strawberry</option>");
print("</select>");
print("</P>");
print("<P>");
print("<input name=add_button type=submit value=Save class=formText>");
print("</P>");
print("</fieldset>");
print("</form>");
?>
At this point - I'm just trying to see the that the values are in my PHP variable in the page that process it - chk_value.php
Here's all the code in the <BODY> tag (pretty simple at this point):
<?php
$subcategory_value = array();
# Get need key value SUBCATEGORY ID
print("The size of the Subcategory array is -> ". sizeof($_POST['subcategory']) . "<BR>" );
for ($i=0;$i<=count($_POST['subcategory']);$i++){
$subcategory_value[] = $_POST['subcategory'];
}
foreach ($subcategory_value as $key => $value)
{ echo $key." - " . $value . "<BR>";
}
?>
I suspect that this code
$subcategory_value[] = $_POST['subcategory'];
in the FOR LOOP is causing the problem.
So when "chk_value.php" executes - How do I properly move the FORM variable captured into a PHP array variable that I can use????
Once I can do this properly - I plan to populate that list with databse values - but I need to be able to process the users selections in the resulting page call.
print("<select name=subcategory[] multiple=multiple >");
I have a simple list of items and I want the user to be able to select more than one item.
I created my FORM variable as an array - so that the $_POST would process this as an array. I know the $_POST item can return an array - but how do you access that information on the other side?
All examples that I seen really do not address how to move the FORM variable back into a PHP array that can be used.
Basic FORM item:
<?php
print("<form action=./chk_value.php method=post name=newitem>");
print("<fieldset>");
print("<legend class=formTitle> Select A Value </legend>");
print("<P class=ptight>");
print("<label for=subcategory>Product Subcategory</label>");
print("<select name=subcategory[] multiple=multiple >");
print("<option value=1>Apple</option>");
print("<option value=2>Apricots</option>");
print("<option value=3>Bananna</option>");
print("<option value=4>Blueberry</option>");
print("<option value=5>Cherry</option>");
print("<option value=6>Cranberry</option>");
print("<option value=7>Figs</option>");
print("<option value=8>Grapes</option>");
print("<option value=9>Oranges</option>");
print("<option value=10>Strawberry</option>");
print("</select>");
print("</P>");
print("<P>");
print("<input name=add_button type=submit value=Save class=formText>");
print("</P>");
print("</fieldset>");
print("</form>");
?>
At this point - I'm just trying to see the that the values are in my PHP variable in the page that process it - chk_value.php
Here's all the code in the <BODY> tag (pretty simple at this point):
<?php
$subcategory_value = array();
# Get need key value SUBCATEGORY ID
print("The size of the Subcategory array is -> ". sizeof($_POST['subcategory']) . "<BR>" );
for ($i=0;$i<=count($_POST['subcategory']);$i++){
$subcategory_value[] = $_POST['subcategory'];
}
foreach ($subcategory_value as $key => $value)
{ echo $key." - " . $value . "<BR>";
}
?>
I suspect that this code
$subcategory_value[] = $_POST['subcategory'];
in the FOR LOOP is causing the problem.
So when "chk_value.php" executes - How do I properly move the FORM variable captured into a PHP array variable that I can use????