我问这个问题之前搜索过。我没有找到答案可能是因为我在搜索时没有使用正确的关键字。
无论如何,这就是我面临的问题:
我想从网站上卖票。每张门票 10 美元。我正在使用 Paypal 接收付款。 html 表单包含以下内容:
<tr>
<td><label for="not">Number of Tickets</label></td>
<td><input name="not" type="text" id="not" /></td>
</tr>
<?php $total = $_POST['not']*10; ?>
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="xxx@xxxx.com">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="amount" value="<?php echo $total; ?>">
<input name="item_name" type="hidden" id="item_name" value="Ticket Purchase" />
<tr>
<td> </td>
<td><input type="submit" value="Pay" name="submit" />
</tr>
问题是总金额是根据购买的门票数量计算的。因此,如果有人输入 5 张票,则总数应为 50 美元,这将用作“金额”变量中的值。但 paypal 并没有收取 $total 值(value)。所以我想知道我应该如何在 ?
提前致谢, 尼萨尔
最佳答案
我认为您最好使用 javascript/jquery 计算总数并以这种方式更新它。
如果你改变
<input type="hidden" name="amount" value="$total">
到
<input type="hidden" name="amount" value="" id="total">
然后在脚本括号内使用像这样的 jquery
$("#not").change(function()
{
var total = $("#not").val() * 10;
$("#total").val(total);
});
尽管您仍然需要进行数据验证,即确保“not”是一个整数。
希望对您有所帮助。
谢谢
尼古拉斯
关于php - 在 Paypal 的 Form 标签中使用 $_POST 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11328908/