【发布时间】:2011-09-07 13:30:33
【问题描述】:
我目前有一个大表格发送给我们的付款授权人(通过 action="paymentautherizerURL" 完成),但是当我将交易存储在我的数据库。
我要么需要在提交之前截取表单数据,以便我可以将其存储在会话中(我们使用的是 PHP / jQuery),要么我也尝试将其发送到获取我需要的信息的中间小脚本,然后使用 jQuery 的 $.post() 重新构建并将数据发送给授权者。
但是,至少在我的最大努力下,第二种方法似乎不起作用。我不确定 $.post 是否正确模拟了表单的发送操作,或者至少我做得不对。
<?php
session_start();
$post = $_POST;
//gets all of the information that beanstream does not return to approved.php, but is still required to make
//a legitimate database entry. gets from the POST and stores in the session array for approved.PHP to access
$_SESSION['approvedArray']['billAddress'] = $_POST['ordAddress1'];
$_SESSION['approvedArray']['billProvince'] = $_POST['ordProvince'];
$_SESSION['approvedArray']['billCountry'] = $_POST['ordCountry'];
$_SESSION['approvedArray']['billPostalCode'] = $_POST['ordPostalCode'];
$_SESSION['approvedArray']['billCity'] = $_POST['ordCity'];
$_SESSION['approvedArray']['shipAddress'] = $_POST['shipAddress1'];
$_SESSION['approvedArray']['shipPostal'] = $_POST['shipPostalCode'];
$_SESSION['approvedArray']['shipCity'] = $_POST['shipCity'];
$_SESSION['approvedArray']['shipProvince'] = $_POST['shipProvince'];
$_SESSION['approvedArray']['shipCountry'] = $_POST['shipCountry'];
session_write_close();
//the javascript below will send what is required to beanstream as though it were sent from the form
<script type='text/javascript'>
$.post(, {
<?php
//rebuild the POST such that "name: value, " except the last name/value will not be followed by a comma
$keys = array_keys($_POST);
for($i = 0; $i < count($_POST); $i++) {
$currentKey = $keys[$i];
$currentPost = $_POST[i];
echo $currentKey . ": " . $currentPost;
if ($i < (count($_POST) - 1)) {
echo ", ";
}
}
?>
});
</script>
?>
通常,交易授权人会将用户重定向到 3 个页面之一(已批准、已拒绝、错误),我们的网站会从那里完成这项工作。但是,它目前卡在这个页面上,这让我觉得它没有正确发送。
我乐于接受各种形式的批评、方法和想法。提前非常感谢,如果需要任何其他信息,请告诉我!
【问题讨论】:
-
您可以在发送之前处理数据
-
是的,@lbu 说的。使用 onsubmit 回调的基本客户端输入验证。这是网络开发 101。
-
Ibu:这就是这个 scriptlet 的目的。它在 POST 中接收大量表单数据,处理它需要的内容,然后重新发送到它的实际目的地。
-
dossy:我忘了 onsubmit= 。这是否是运行此 scriptlet 但没有 jQuery 重定向的合适位置?谢谢。
-
等等,你在关闭第一个标签之前启动了另一个
<?php标签?
标签: php jquery forms post beanstream