PHP/Ajax收集和传递表单数据
我需要用php表单收集输入(“x_amount”),然后将其发布到生成哈希的页面,然后将其发布到第三方站点。我不希望客户有一个两步流程,所以可以用ajax和php来完成吗?这是我到目前为止所拥有的,但它需要调整(我想是吧?)PHP/Ajax收集和传递表单数据,php,ajax,forms,Php,Ajax,Forms,我需要用php表单收集输入(“x_amount”),然后将其发布到生成哈希的页面,然后将其发布到第三方站点。我不希望客户有一个两步流程,所以可以用ajax和php来完成吗?这是我到目前为止所拥有的,但它需要调整(我想是吧?) 我认为您可以通过在带有“x_amount”字段的blur事件上创建ajax请求来实现这一点。 如果生成哈希需要php,则如下所示: 表格: 好的,我看到firstdata.com实际上建议你这么做。我设法为你做了点东西 您必须使用ajax,将客户机输入的金额发布到同一页面
我认为您可以通过在带有“x_amount”字段的blur事件上创建ajax请求来实现这一点。
如果生成哈希需要php,则如下所示:
表格:
好的,我看到firstdata.com
实际上建议你这么做。我设法为你做了点东西
您必须使用ajax,将客户机输入的金额发布到同一页面,进行处理并返回表单。只有在处理数据时才使用Sumbit表单
我为你制作了整个脚本,因为它在某个时刻变得令人沮丧,因为它想知道如何去做
test.php
<?php
if(isset($_POST['amount']) && ($_POST['amount'] != '')){
$x_amount = $_POST['amount'];
$x_login = "xxx-xxx"; // Take from Payment Page ID in Payment Pages interface
$transaction_key = "xxxxxxx"; // Take from Payment Pages configuration interface
$x_currency_code = "CAD"; // Needs to agree with the currency of the payment page
srand(time()); // initialize random generator for x_fp_sequence
$x_fp_sequence = rand(1000, 100000) + 123456;
$x_fp_timestamp = time(); // needs to be in UTC. Make sure webserver produces UTC
// The values that contribute to x_fp_hash
$hmac_data = $x_login . "^" . $x_fp_sequence . "^" . $x_fp_timestamp . "^" . $x_amount . "^" . $x_currency_code;
$x_fp_hash = hash_hmac('MD5', $hmac_data, $transaction_key);
$values = array('login' => $x_login, 'amount' => $x_amount, 'sequence' => $x_fp_sequence, 'timestamp' => $x_fp_timestamp, 'hash' => $x_fp_hash, 'currency' => $x_currency_code);
echo json_encode($values);
die;
}
?><html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<script type="text/javascript">
var processed = false;
function makeProcessed(type){
processed = type;
}
function prepareForm(){
$('#submitPayment').val('Please wait ...');
var processPayment = $.ajax({
type: 'POST',
url: "test.php",
data: {"amount": $('#x_my_amount').val()},
dataType: 'json',
async: false,
success: function(data) {
$('#x_login').val(data.login);
$('#x_amount').val(data.amount);
$('#x_fp_sequence').val(data.sequence);
$('#x_fp_timestamp').val(data.timestamp);
$('#x_fp_hash').val(data.hash);
$('#x_currency_code').val(data.currency);
if(data.hash){
makeProcessed(true);
}
}
});
return processed;
};
</script>
</head>
<body>
<form action="https://globalgatewaye4.firstdata.com/pay" method="POST" id="payment" onsubmit="return prepareForm();">
<input type="hidden" name="x_show_form" value="PAYMENT_FORM"/>
<input type="hidden" name="x_test_request" value="FALSE"/>
<input name="x_login" id="x_login" type="hidden" value="">
<input name="x_amount" id="x_amount" type="hidden" value="">
<input name="x_fp_sequence" id="x_fp_sequence" type="hidden" value="">
<input name="x_fp_timestamp" id="x_fp_timestamp" type="hidden" value="">
<input name="x_fp_hash" id="x_fp_hash" type="hidden" value="" size="50">
<input name="x_currency_code" id="x_currency_code" type="hidden" value="">
Enter Payment Amount:<br>
<input type="text" name="x_my_amount" id="x_my_amount" />
<input type="submit" id="submitPayment" value="Pay with Payment Pages" />
</form>
</body>
</html>
var=false;
函数makeProcessed(类型){
处理=类型;
}
函数prepareForm(){
$(#submitPayment').val('请稍候…');
var processPayment=$.ajax({
键入:“POST”,
url:“test.php”,
数据:{“金额”:$('x#u my_金额').val(),
数据类型:“json”,
async:false,
成功:功能(数据){
$('x#u login').val(data.login);
$('x#u amount').val(data.amount);
$('#x_fp_sequence').val(data.sequence);
$('x#fp_timestamp').val(data.timestamp);
$('#x_fp_hash').val(data.hash);
$('x#u currency_code').val(data.currency);
if(data.hash){
makeProcessed(true);
}
}
});
已处理退货;
};
输入付款金额:
您的问题可以通过Ajax解决,但我认为这不好,您的登录和哈希应该是服务器端的。谢谢Mihai!我愿意听取关于如何使用PHP实现服务器端的建议。我只需要一个基本的html页面来收集客户的金额(也可能是发票),然后将其发布到第三方安全计费网站,他们在那里收集其余的计费信息并进行处理。谢谢!我明白你的想法。。。要从“真实数量”字段获取模糊的x数量。。。聪明。那么ajax函数缺少什么呢$('#real amount').on('blur',function(){$.ajax({success:function(data){//返回的哈希应该放在这里的x#amount字段$('#x-amount').val(data);}});我错过了一些ajax设置,例如url、类型等。你可以在这里读到更多关于他们的信息:这行吗?$('#real amount').on('blur',function(){$.ajax({url:'payment.php',键入:“GET”,数据:数据,缓存:false,成功:函数(数据){$(“#x-amount”).val(data);}}}});在超级重复答案处完成代码
Enter Payment Amount:<br>
<input type="text" name="real_amount" id="real-amount"/>
<input type="hidden" name="x_amount" id="x-amount" />
$('#real-amount').on('blur', function() {
$.ajax({
....
success: function(data) {
// returned hash should be put in x_amount field here
$('#x-amount').val(data);
}
});
});
<?php
if(isset($_POST['amount']) && ($_POST['amount'] != '')){
$x_amount = $_POST['amount'];
$x_login = "xxx-xxx"; // Take from Payment Page ID in Payment Pages interface
$transaction_key = "xxxxxxx"; // Take from Payment Pages configuration interface
$x_currency_code = "CAD"; // Needs to agree with the currency of the payment page
srand(time()); // initialize random generator for x_fp_sequence
$x_fp_sequence = rand(1000, 100000) + 123456;
$x_fp_timestamp = time(); // needs to be in UTC. Make sure webserver produces UTC
// The values that contribute to x_fp_hash
$hmac_data = $x_login . "^" . $x_fp_sequence . "^" . $x_fp_timestamp . "^" . $x_amount . "^" . $x_currency_code;
$x_fp_hash = hash_hmac('MD5', $hmac_data, $transaction_key);
$values = array('login' => $x_login, 'amount' => $x_amount, 'sequence' => $x_fp_sequence, 'timestamp' => $x_fp_timestamp, 'hash' => $x_fp_hash, 'currency' => $x_currency_code);
echo json_encode($values);
die;
}
?><html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<script type="text/javascript">
var processed = false;
function makeProcessed(type){
processed = type;
}
function prepareForm(){
$('#submitPayment').val('Please wait ...');
var processPayment = $.ajax({
type: 'POST',
url: "test.php",
data: {"amount": $('#x_my_amount').val()},
dataType: 'json',
async: false,
success: function(data) {
$('#x_login').val(data.login);
$('#x_amount').val(data.amount);
$('#x_fp_sequence').val(data.sequence);
$('#x_fp_timestamp').val(data.timestamp);
$('#x_fp_hash').val(data.hash);
$('#x_currency_code').val(data.currency);
if(data.hash){
makeProcessed(true);
}
}
});
return processed;
};
</script>
</head>
<body>
<form action="https://globalgatewaye4.firstdata.com/pay" method="POST" id="payment" onsubmit="return prepareForm();">
<input type="hidden" name="x_show_form" value="PAYMENT_FORM"/>
<input type="hidden" name="x_test_request" value="FALSE"/>
<input name="x_login" id="x_login" type="hidden" value="">
<input name="x_amount" id="x_amount" type="hidden" value="">
<input name="x_fp_sequence" id="x_fp_sequence" type="hidden" value="">
<input name="x_fp_timestamp" id="x_fp_timestamp" type="hidden" value="">
<input name="x_fp_hash" id="x_fp_hash" type="hidden" value="" size="50">
<input name="x_currency_code" id="x_currency_code" type="hidden" value="">
Enter Payment Amount:<br>
<input type="text" name="x_my_amount" id="x_my_amount" />
<input type="submit" id="submitPayment" value="Pay with Payment Pages" />
</form>
</body>
</html>