nick_singh Posted June 24, 2009 Share Posted June 24, 2009 Hello there, First post! I am new to PHP coding and am developing a small website for a family friend. What I have done is create a dynamic form that creates a whole range of select fields depedning on a row in the Database. This part is fine. However, I am running into issues on the processing page the form data is sent to. How would I go about pulling out the users selection on this page? I am used to grabbing data using the $_POST function, but how would I do this with dynamic generated form forms? I assume I would use a loop and maybe arrays? but have no idea where to start! I am trying to get hold of each value in "name="extras_<?= $itemID; ?>_select" My form code is below and thanks for any help anyone can offer. Nick <? $sqlstring = "SELECT * FROM `EXTRAS_DESCRIPTION` WHERE `ITEM_TYPE` = 'FOOD_DRINK' AND `ACTIVE` = 'YES' ORDER BY `ID` ASC"; $getdetails = mysql_query($sqlstring); //$row = mysql_fetch_ara($getdetails); while ($row = mysql_fetch_array($getdetails)) { $itemID = $row['ID']; $itemnameDB = $row['ITEM_NAME']; $itemdescriptionDB = $row['ITEM_DESCRIPTION']; $itemtypeDB = $row['ITEM_TYPE']; $itempriceDB = $row['ITEM_PRICE']; $itemquantityDB = $row['ITEM_QUANTITY']; $itemnameDB = stripslashes($itemnameDB); $itemdescriptionDB = stripslashes($itemdescriptionDB); ?> <tr> <td align="center"><div align="center"><img align="middle" src="../images/extras/<?= $itemID; ?>"/></div></td> <td><strong> <?= $itemnameDB; ?> </strong> <br /><a href="#" onmouseover="Tip('<?= $itemdescriptionDB; ?>')" onmouseout="UnTip()">(more information)</a> </td> <td>€<? echo number_format($itempriceDB, 2);?></td> <td><select name="extras_<?= $itemID; ?>_select" value="yes" id="extras_<?= $itemID; ?>_select"> <option rel="none" selected="selected">0</option> <option rel="none">1</option> <option rel="none">2</option> <option rel="none">3</option> <option rel="none">4</option> <option rel="none">5</option> <option rel="none">6</option> <option rel="none">7</option> <option rel="none">8</option> <option rel="none">9</option> </select></td> </tr> <? } Link to comment https://forums.phpfreaks.com/topic/163534-how-to-grab-user-input-from-a-dynamic-form/ Share on other sites More sharing options...
J.Daniels Posted June 24, 2009 Share Posted June 24, 2009 There are probably a few ways to do it, but to build on what you have, I would create a hidden input field and set the value to $itemID. Then you'll be able to reference that when you get your $_POST variables: $_POST['extras_'.$_POST['itemID']] Link to comment https://forums.phpfreaks.com/topic/163534-how-to-grab-user-input-from-a-dynamic-form/#findComment-862828 Share on other sites More sharing options...
aggrav8d Posted June 24, 2009 Share Posted June 24, 2009 j.daniels - won't help when there are multiple selects on a single page. nick, change the name of the inputs to extras[$item_id]. That way you'll get a _POST like array { 'extras' =>array( '1'=>'1', '2'=>'5', '3'=>'', ) ) which is a lot easier to process. Link to comment https://forums.phpfreaks.com/topic/163534-how-to-grab-user-input-from-a-dynamic-form/#findComment-862831 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.