我的资料都准备好了。我只需要把它们保存在我的数据库里。但当我点击submit时,没有数据被提取。我的所有数据都是使用.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");
});

我的控制器:
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>";

现在应该可以了。

07-27 17:55