来自jQuery的输入值未在表单提交中被提取

时间:2017-06-16 07:24:11

标签: javascript php jquery html codeigniter

我准备好了所有数据。我需要做的就是将它们保存在我的数据库中。但是当我点击提交时,没有数据被提取。我的所有数据都是使用.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,所以我真的想让表单提交工作。

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

1 个答案:

答案 0 :(得分:2)

从输入中移除disabled属性,<{p>}字段未被表单

选中
disabled

现在应该可以了。