php - 希望 Paypal 订阅按钮在重定向付款之前向我提交页面中的表单

标签 php html forms paypal

您好,我在同一页面上有一个表单和一个 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-->

最佳答案

在这种情况下,这是一个非常糟糕的解决方案,但可以在将浏览器重定向到 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>

关于php - 希望 Paypal 订阅按钮在重定向付款之前向我提交页面中的表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33028505/

相关文章:

javascript - 动态菜单和 Javascript 滚动

javascript - 使用js和php更改数据库中数据的顺序

forms - Angular 5 - 禁用单选按钮

JQuery 在提交之前需要复选框和单选按钮

php - Symfony + Docker,连接被拒绝

php - 在 Woocommerce 中隐藏特定产品的特定运输方式

javascript - 如何创建在使用 Ajax 或刷新页面时不刷新的顶部栏?

javascript - 如何为一个简单的 donut 为 SVG Circle 的笔触添加边距

c# - 如何在 C# 字符串中显示 HTML 内容?

html - 无法正确显示窗体边框