Jump to content

Recommended Posts

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.

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 />";
}
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.