我正在以一种选择形式使用两个按钮。一个按钮用于贝宝,另一个按钮用于bitpay。我尝试使用JavaScript和php代码将表单数据发布到另一页上。但是它不起作用。
这是代码-
//Pay with Bitpay
$('#lvlBtcPay').click(function(e){` `var amounts =
$("#valRechargeSelect").val();
document.getElementById('PayBitpay1').value = amounts; `
document.bitpayForm.submit();
});
//Pay with Paypal
$('#lvlRechargeBtnPay').click(function(e){
var amount = $("#valRechargeSelect").val();
document.getElementById('montoPaypal').value =
amount;`document.paypalForm.submit()
});
//Form for bitpay payment
<form action="/displaydata.php" method="post" name="bitpayForm">
<input type="hidden" id="PayBitpay1" name="Amount" value=""></form>
//Form for paypal payment
<form action="/paypal.php" method="post" name="paypalForm">
<input type="hidden" id="montoPaypal" name="amount" value=""> </form>
//Here is the select options
<select id="valRechargeSelect" class="form-control" >
<option value="0">Selecciona un monto</option>
<option value="5">$5</option>
<option value="10">$10</option>
<button class="btn btn-success" id="lvlRechargeBtnPay">Pay With
Paypal</button>
<button class="btn btn-success" id="lvlBtcPay" type="Submit" name="Submit"
>Pay With BTC</button>
//Here is the PHP code to display or post data -
<?php
if(isset($_POST['#valRechargeSelect'])){ `$selected_val = $_POST['amount'];
echo "You have selected Amount :" .$selected_val;
}?>
答案 0 :(得分:1)
我已经根据您的代码创建了一个代码段。您可以取消注释提交代码以提交表单。
在您的PHP代码中,$_POST['#valRechargeSelect']
#valRechargeSelect
不是有效的发布密钥,因为select
中不存在ID为valRechargeSelect
的{{1}}。 / p>
提交表单时,您的form
和$_POST['amount']
文件中可以有displaydata.php
。
paypal.php
//Pay with Bitpay
$('#lvlBtcPay').click(function(e){
var amount = $("#valRechargeSelect").val();
document.getElementById('PayBitpay1').value = amount;
console.log(amount);
console.log('Submit form to: ',document.bitpayForm.action)
//Uncomment the line below to submit the form.
//document.bitpayForm.submit();
});
//Pay with Paypal
$('#lvlRechargeBtnPay').click(function(e){
var amount = $("#valRechargeSelect").val();
document.getElementById('montoPaypal').value = amount;
console.log('Submit form to: ',document.paypalForm.action)
console.log(amount);
//Uncomment the line below to submit the form.
//document.paypalForm.submit()
});