如何传递提交php的动态表单的字段名称和值 [英] How to pass field name and value of dynamic form on submit php
问题描述
name =options []
然后执行以下操作:
foreach($ options as $ option){
//添加到db
}
然而,只给我一些值,我需要知道optionID以及 b
$ b
可以这样做:
name =<?echo $ optionID;?>
的下拉菜单,但是当我尝试处理时,我不知道该表单中包含了什么optionID提交的数据。在表单中增加字段时,如何同时传递optionID和选择的值?
可以使数组多维。这样的事情可能适用于你:
name =options [<?php echo $ optionID;?>] [ ]
foreach($ _POST ['options'] as $ ID){
foreach($ ID as $ value){
// stuff
}
}
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 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
}
}
这篇关于如何传递提交php的动态表单的字段名称和值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!