使用POST变量传递表格数据

3
基本上我有一个表格,其中包含来自数据库的许多数字,列出了总计/小计。我不打算将任何总计添加到数据库中,但我需要将总数从一个页面传递到另一个页面。我似乎无法使用PHP正确地将它们作为post变量传递...我想知道首先这是否是一种不好的策略,其次我应该做什么?
如果可能的话,我该怎么做?我无法从$_POST['tdname']中获取< td >之间的文本。
示例代码:
<form method="POST" action="newcivilreport2.php">

            <div style="width:800px;text-align:left;margin:0 auto;padding-bottom:5px;">A. PENDING BALANCE</div>
            <table border="1" style="width:800px;" ID="tableA">
            <th style="width:40%;"></th>
            <th style="width:15%;">Civil</th>
            <th style="width:15%;">Asbestos</th>
            <th style="width:15%;">Domestic</th>
            <th style="width:15%;">Total</th>
            <tr>
            <td>1. Pending Balance from Previous Month</td>
            <td id="PendingCivil" name="PendingCivil">66</td>
            <td id="PendingAsbestos">0</td>
            <td id="PendingDomestic">0</td>
            <td id="PendingTotal">0</td>
            </tr>
            </table> 
<input type="submit" value="Save and Continue -->"></form></div>

newcivilreport2.php:

<?php
    $_POST['PendingCivil'];
?>

可以将数据作为POST变量传递。你能发一些你的代码吗,这样我们就可以尝试弄清楚你在做什么? - James
2个回答

7

POST 只会发送像 <input type='text|file|hidden|ect' /> 这样的输入。也许您想使用 AJAX。例如:

<table id="tData">
     <tbody>
         <tr>
             <td class='dataVal1'>100</td>
      ...

$(document).ready(function() {
    var toServer = {};
    var data = $('#tData tbody tr td').each(function(key, value) {
        toServer[$(this).attr('id')] = $(this).text();
    });
    $.ajax({
        url: 'page.php',
        data: toServer,
        type: 'POST'
    })
});

3
<td>

请使用隐藏域进行提交:
http://www.w3schools.com/tags/att_input_type.asp

...
<td>1. Pending Balance from Previous Month</td>
<td id="PendingCivil">66<input type="hidden" name="PendingCivil" value="66"></td>
...

标签中的标签不能提供表单的值。此外,它是否处于表单中?

问题在于该值被设置为66,而根据计算结果,该值将会改变。 - Jeff
然后使用一些JavaScript来在计算后更新值。jQuery使得生活更轻松! - afuzzyllama

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接