【发布时间】:2018-07-12 12:35:24
【问题描述】:
所以我有这样的东西(为了简单起见,是准系统):
<?php
$paymentResult = 'Unknown';
function processPayment(){
// Process all payment values from form1 and retrieve the result of the transaction.
$GLOBALS['paymentResult'] = 'Your payment was completed successfully!';
}
?>
<form name="form1" method="POST" onsubmit="return processPayment();" action="<?php echo 'checkout_s.php?result=' . $paymentResult; ?>">
<!--Additional Credit Card Payment Controls-->
<input type="submit" value="Process Payment">
</form>
processPayment() 方法显然有额外的消息和逻辑,以防支付失败等。
我的问题是,无论我在 processPayment() 函数中将 $paymentResult 设置为什么,它总是将“未知”作为
当我在 checkout_s.php 上回显 $_REQUEST['result']; 时的 post 变量。
我非常有信心正确使用全局变量。有人可以就如何正确修改代码或提供其他方法提供建议吗?我不想将信用卡信息作为帖子变量传递,所以我在同一页面上处理它。我要做的就是将事务的结果传递到操作页面。
【问题讨论】:
-
您是否真的将您的 javascript 和 PHP 函数命名为相同的名称,或者您是否混淆了客户端和服务器端代码并假设
onsubmit="return processPayment() "会以某种方式触发 PHP 函数? -
是的,它们是同名的。
标签: php html forms action onsubmit