poleposters Posted June 2, 2010 Share Posted June 2, 2010 Hi, I have a form that is dynamically generated. It pulls a number of items from the database and presents each one with a select menu next to it. The select menu presents a number of options that apply to each individual item. ie ITEM_47---<select>-- ITEM_56---<select>-- ITEM_32---<select>-- ITEM_63---<select>-- Now the problem I have is that if I use the ITEM_ID as the name of each field I wont be able to process the form because the process script won't know how to refer to the $_POST data in order to capture it. However if I give he fields generic names, then I won't be able to link each select menu with an ITEM_ID. It seems like a pretty basic task. I'm certain there is a solution. Please let me know if I need to clarify. Thanks. Link to comment https://forums.phpfreaks.com/topic/203595-how-do-i-handle-this-dynamically-generated-form/ Share on other sites More sharing options...
PFMaBiSmAd Posted June 2, 2010 Share Posted June 2, 2010 Use a HTML array in your form, where the array's index is the item id and then just iterate over the array in the php code - <form action="" method="post"> <select name="sel[iTEM_47]"> <option value="abc">option abc</option> <option value="def">option def</option> </select> <select name="sel[iTEM_56]"> <option value="abc">option abc</option> <option value="def">option def</option> </select> <input type="submit"> </form> <?php foreach($_POST['sel'] as $key => $value){ echo "Key: $key, Value: $value<br />"; } ?> Link to comment https://forums.phpfreaks.com/topic/203595-how-do-i-handle-this-dynamically-generated-form/#findComment-1066472 Share on other sites More sharing options...
poleposters Posted June 2, 2010 Author Share Posted June 2, 2010 Fantastic! Thank you. So simple. Link to comment https://forums.phpfreaks.com/topic/203595-how-do-i-handle-this-dynamically-generated-form/#findComment-1066478 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.