Jump to content

how to grab user input from a dynamic form


nick_singh

Recommended Posts

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>

	<?	}

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.