gpt4 book ai didi

javascript - 来自 jQuery 的输入值未在表单提交时被提取

转载 作者:行者123 更新时间:2023-11-27 23:13:31 26 4
gpt4 key购买 nike

我已准备好所有数据。我需要做的就是将它们保存在我的数据库中。但是当我点击提交时,没有数据被提取。我的所有数据都是使用 .append() 从我的 js 文件生成的。

这是我的 HTML 文件:

<table>
<?php
$attributes = array('class' => 'form form-horizontal', 'id' => 'receiving-form', 'role' => 'form', 'method' => 'POST');
echo form_open('oss/admin/save_receiving', $attributes);
?>
<tbody>
<tr id="batch-no-data">
<td colspan="4" class="text-center">No data yet.</td>
</tr>
</tbody>
</table>
<?php echo form_close(); ?>
<div class="col-md-6 text-right">
<button id="add_ExpenseRow" class="btn btn-lg btn-info">Add</button> <button type="submit" form="receiving-form" class="btn btn-lg btn-info">Save</button>
</div>

我生成数据的 JS 文件:

var batch_row, batch_ctr;
$( "#new-batch" ).click(function() {
$('#receiving-box').css('display', 'block');

if($('#batch-count-db').val() == 0){
$('tr#batch-no-data').css('display', 'none');
}
var fullDate = new Date();
var currentDate = ( '0' + (fullDate.getMonth()+1) ).slice( -2 ) + '/' + fullDate.getDate() + '/' + fullDate.getFullYear();
var batch_ctr = $('#last-batch-no').val();

batch_row = "<tr><td><input form='receiving-form' name='batch_no' class='form-control show_disabled' type='text' value='"+$('#last-batch-no').val()+"' id='batch_no-"+batch_ctr+"' disabled/></td><td><input name='batch_date' form='receiving-form' class='form-control show_disabled' type='text' value='"+currentDate+"' disabled id='batch_cur_date-"+batch_ctr+"'/></td><td><input form='receiving-form' name='batch_qty' id='qty-"+batch_ctr+"' class='form-control show_disabled' type='text' value='"+$('#receiving-box-table tbody>tr').length+"' disabled/></td><td></td></tr>";

$('#receiving-batch-table tbody').append(batch_row);
$( "#new-batch" ).attr("disabled", "disabled");
});

我的 Controller :

public function save_receiving() {
// Batch data
$batch_no = $this->input->post('batch_no');
$batch_date = $this->input->post('batch_date');
$batch_qty = $this->input->post('batch_qty');
$batch_data = array(
'staff_id' => $staff_id,
'batch_no' => $batch_no,
'quantity' => $batch_qty
);
print_r($this->input->post()); die();
}

我错过了什么?我不想使用 Ajax,所以我真的想让表单提交工作。

非常感谢任何帮助。谢谢!

最佳答案

从 inpute 的 disabled 属性中移除 disabled 字段不会被表单拾取

batch_row = "<tr><td><input form='receiving-form' name='batch_no' class='form-control show_disabled' type='text' value='"+$('#last-batch-no').val()+"' id='batch_no-"+batch_ctr+"' /></td><td><input name='batch_date' form='receiving-form' class='form-control show_disabled' type='text' value='"+currentDate+"'  id='batch_cur_date-"+batch_ctr+"'/></td><td><input form='receiving-form' name='batch_qty' id='qty-"+batch_ctr+"' class='form-control show_disabled' type='text' value='"+$('#receiving-box-table tbody>tr').length+"' /></td><td></td></tr>";

现在应该可以了。

关于javascript - 来自 jQuery 的输入值未在表单提交时被提取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44583263/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com