开发者

How to pass field name and value of dynamic form on submit php

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
  }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜