I have a form that has fixed fields as well as dynamic fields created from a database. the fields could be different every time and they are dropdowns with options like color size etc.I could name the dropdowns like this:
name="options[]"
and then do something like:
foreach($options as $option) {
//add to db
}
however that only gives me the values and I need to know the optionID as well
I could 开发者_Python百科do somethign like:
name="<? echo $optionID; ?>"
for the dropdown but I don't know what optionID's were included in the form when I try to process the submitted data. how do I pass both the optionID and it's selected value when adding fields to a form dynammically?
You can make the array multidimensional. Something like this might work for you:
name="options[<?php echo $optionID;?>][]"
foreach ($_POST['options'] as $ID) {
foreach ($ID as $value) {
// stuff
}
}
精彩评论