您好,我在同一页面上有一个表单和一个paypal订阅按钮。我想在点击提交表单(通过电子邮件发送给我)之前订阅按钮,然后重定向到paypal付款。
<!--THE CONTACT FORM-->
<center>
<form action="createUser.php" method="POST">
<input id="email" type="email" name="email" placeholder= "Email Address" required value= <?php echo htmlspecialchars($_POST['email1']); ?> >
<br>
<input id="fullName" type="text" name="fullName" placeholder="Your Full Name" required value= <?php echo htmlspecialchars($_POST['fullName1']); ?>>
<br>
<input id="tel" type="tel" name="tel" placeholder="Your Number" required>
<br>
<center>
</center>
</form>
<!--THE CONTACT FORM-->
<!--Paypal Button-->
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="DLNYHMF3A6TUE">
<input type="submit" value="Add to Cart" name="submit" class="paypal_btn">
</form>
<!--Paypal Button-->
答案 0 :(得分:0)
在这种情况下,它是一个非常糟糕的解决方案,但可以在将浏览器重定向到Paypal结账之前通过AJAX向您的服务器提交POST。
<script type="text/javascript">
document.getElementsByClassName('paypal_btn')[0].onclick = function(){
var xhttp = new XMLHttpRequest();
xhttp.open("POST", "createUser.php", true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.send("email="+document.getElementById('email').value+"&fullName="+document.getElementById('fullName').value+"&tel="+document.getElementById('tel').value);
}
</script>