[英]dynamically created textbox does not post value
This is my code for dynamically create textbox 这是我用于动态创建文本框的代码
$("#addfee tr").last().after("<tr><input name=\'Detail[" + $("#invoicedetail-item_id").val() +"][item_id]\' type=\'hidden\' value=\'" + $("#invoicedetail-item_id").val()+ "\' >"
+"<td><input type=\'text\' value=\' "+ $("#invoicedetail-item_id").find(":selected").text()+"\'readonly=\'readonly\'class=\'form-control\'></td>"
+"<td><input type=\'text\' name=\'Detail[" + $("#invoicedetail-tax").val() + "][tax]\' value=\'"+$("#invoicedetail-tax").val() +"\' readonly=\'readonly\'class=\'form-control\'></td>"
+"<td><input type=\'text\' name=\'Detail[" + $("#invoicedetail-unit_price").val() + "][unit_price]\' value=\'"+$("#invoicedetail-unit_price").val() +"\' readonly=\'readonly\' class=\'form-control\'></td>"
+"<td><input type=\'text\' name=\'Detail[" + $("#invoicedetail-quantity").val() + "][quantity]\' value=\'"+$("#invoicedetail-quantity").val() +"\' readonly=\'readonly\'class=\'form-control\'></td>"
+"<td><button>X</button></td></tr>");
}
in view dynamically new rows are added 在视图中动态添加新行
But in controller 但是在控制器中
But it doesn't go to the if(isset($_POST['Detail'])
condition Help me plz....... 但这并没有达到
if(isset($_POST['Detail'])
条件。
First of all use isset() and not isset[) and are you posting with method POST or GET? 首先使用isset()而不是isset [),您是否要使用POST或GET方法发布?
if(isset($_POST['Detail'])) {
var_dump($_POST['Detail'];
}
if(!isset($_POST['Detail']) && isset($_GET['Detail'])) {
echo 'Form method is wrong, GET is used by default not POST';
}
因为您应该检查if(isset[$_POST['Detail']))
If you are submitting form using Jquery. 如果您使用Jquery提交表单。 then use following code for submitting dynamically added elements
然后使用以下代码提交动态添加的元素
$('#buttonSubmit').on('click', 'button', function(){
// do something
});
https://api.jquery.com/on/#on-events-selector-data-handler https://api.jquery.com/on/#on-events-selector-data-handler
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.