Retrieving array elements from a web form
Posted: Wed Mar 07, 2007 12:45 pm
I have a web form that has hidden fields that are dynamically generated. I want to be able to pass these to another page on submission, and I can't seem to figure out how to do it.
$namearray is an array that has the product names
Normally on the page that handles the form submission, we handle the submitted values thus:
How do I do the same thing for a field that is based on an array? for instance, in the page that has the form, if 5 products were selected, the dynamically generated text fields would be:
<input type='text' name='productname0' value='paper' >
<input type='text' name='productname1' value='pencil' >
<input type='text' name='productname2' value='pen' >
<input type='text' name='productname3' value='notebook' >
<input type='text' name='productname4' value='eraser' >
How would I submit these fields' values to another page?
Thanks...
$namearray is an array that has the product names
Code: Select all
<?php
for ($i=0;$i<sizeof($namearray);$i++){
?>Code: Select all
<input type='text' name='productname<?= $i ?>' value='<?= $namearray[$i]?>'Code: Select all
<?php
}
?>Normally on the page that handles the form submission, we handle the submitted values thus:
Code: Select all
$name = $_POST['name'];How do I do the same thing for a field that is based on an array? for instance, in the page that has the form, if 5 products were selected, the dynamically generated text fields would be:
<input type='text' name='productname0' value='paper' >
<input type='text' name='productname1' value='pencil' >
<input type='text' name='productname2' value='pen' >
<input type='text' name='productname3' value='notebook' >
<input type='text' name='productname4' value='eraser' >
How would I submit these fields' values to another page?
Thanks...