using $_POST to retrive dynamicly created variable
Posted: Tue Nov 03, 2009 1:07 pm
So I have a page that uses a loop to create multiple forms on a page that edit data stored in a sql db. Each form is sepperated using the unique id that given in the sql db. Here is a sample of what I'm working with:
On products_edit2.php how would I receive the information sent by warehouse<? echo $id; ?>[] ? I know that if the value name is know I can use:
But if I am dynamically appending the unique id to the end of the name, how can this data be captured? Is there a way to use wildcards, such as:
or is there a way to pass the id and use it is some way such as:
Any help on this is very much appreciated.

Code: Select all
<form action="products_edit2.php" name="updateBPI<? echo $id; ?>" id="updateBPI<? echo $id; ?>" method="post" enctype="application/x-www-form-urlencoded">
<input name="id" type="hidden" id="<? echo $id; ?>" />
<select name="warehouse<? echo $id; ?>[]" id="warehouse<? echo $id; ?>" size="3" multiple="multiple" >
<option value="1">warehouse1</option>
<option value="2">warehouse2</option>
<option value="3">warehouse3</option>
</select>
<input name="Submit" type="submit" id="Submit" value="Update" />
</form>
<hr />
<form action="products_edit2.php" name="updateBPI<? echo $id; ?>" id="updateBPI<? echo $id; ?>" method="post" enctype="application/x-www-form-urlencoded">
<select name="warehouse<? echo $id; ?>[]" id="warehouse<? echo $id; ?>" size="3" multiple="multiple" >
<option value="1">warehouse1</option>
<option value="2">warehouse2</option>
<option value="3">warehouse3</option>
</select>
<input name="Submit" type="submit" id="Submit" value="Update" />
</form>
Code: Select all
is_array ($_POST['warehouse']) ? $warehouse=implode(",",$_POST['warehouse']) : $warehouse=$_POST['warehouse'];
Code: Select all
is_array ($_POST['warehouse%%']) ? $warehouse=implode(",",$_POST['warehouse%%']) : $warehouse=$_POST['warehouse%%'];
Code: Select all
$id=$_POST['id'];
warehouse=$_POST['warehouse$id']