POST动态添加表单字段?

时间:2015-05-07 20:46:32

标签: php sql forms

如何将动态添加的表单字段添加到POST?这是我到目前为止的代码,第一个字段是唯一添加到POST的字段。

表格:

<form class="form-horizontal" action="index.php" method="post">
    <td>
    <input class="case" type="checkbox"/></td>
    <td>
    <input type="text" data-type="ID" name="idNo[]" id="idNo_1" class="form-control autocomplete_txt" autocomplete="off"></td>
    <td>
    <input type="text" data-type="model" name="model[]" id="model_1" class="form-control autocomplete_txt" autocomplete="off"></td>
    <td>
    <input type="text" data-type="description" name="description[]" id="description_1" class="form-control autocomplete_txt" autocomplete="off">
    </td>   
    <td>
    <input type="text" data-type="cost" name="cost[]" id="cost_1" class="form-control autocomplete_txt" autocomplete="off"></td>
    <td>
    <input type="text" data-type="retail" name="retail[]" id="retail_1" class="form-control autocomplete_txt" autocomplete="off"></td>
    <td><input type="number" name="quantity[]" id="quantity_1" class="form-control autocomplete_txt" autocomplete="off"></td>
</tr>

表单动态添加/删除:

<div class='row'>
    <div class='col-xs-12 col-sm-3 col-md-3 col-lg-3'>
        <button class="btn btn-danger delete" type="button">- Delete</button>
        <button class="btn btn-success addmore" type="button" id="Add">+ Add More</button>
    </div>
</div>

和....

var i=$('table tr').length;
$(".addmore").on('click',function(){
    html = '<tr>';
    html += '<td><input class="case" type="checkbox"/></td>';
    html += '<td><input type="text" data-type="ID" name="idNo[]" id="idNo_'+i+'" class="form-control autocomplete_txt" autocomplete="off"></td>';
    html += '<td><input type="text" data-type="model" name="model[]" id="model_'+i+'" class="form-control autocomplete_txt" autocomplete="off"></td>';
    html += '<td><input type="text" data-type="description" name="description[]" id="description_'+i+'" class="form-control autocomplete_txt" autocomplete="off"></td>';
    html += '<td><input type="text" data-type="cost" name="cost[]" id="cost_'+i+'" class="form-control autocomplete_txt" autocomplete="off"></td>';
    html += '<td><input type="text" data-type="retail" name="retail[]" id="retail_'+i+'" class="form-control autocomplete_txt" autocomplete="off"></td>';
    html += '<td><input type="text" data-type="quantity" name="quantity[]" id="quantity_'+i+'" class="form-control changesNo" autocomplete="off" onkeypress="return IsNumeric(event);" ondrop="return false;" onpaste="return false;"></td>';
    html += '<td><input type="text" name="total[]" id="total_'+i+'" class="form-control totalLinePrice" autocomplete="off" onkeypress="return IsNumeric(event);" ondrop="return false;" onpaste="return false;"></td>';
    html += '</tr>';
    $('table').append(html);
    i++;
});

关闭表格(页面末尾):

<div class="form-actions">
  <button type="submit" class="btn btn-success">Create</button>
  <a class="btn" href="index.php">Back</a>
</div>

我还没有开始使用将POST数据保存到我的sql数据库所需的php,我仍在努力使POST结果正确。

0 个答案:

没有答案