所以我在这里有这个表格,应该按行动指示发送到create_subscription.php
。
<form action="create_subscription.php" method="post" id="stripe-payment-form">
<div class="form-row">
<label for="card-element">
Credit or debit card
</label>
<div id="card-element"></div>
<div id="card-errors" role="alert"></div>
</div>
<br>
<button id='submitmystripepayment' class="btn btn-success">Submit Payment</button>
</form>
这是提交表单的JavaScript
// Handle form submission
var form = document.getElementById('stripe-payment-form');
form.addEventListener('submitmystripepayment', function(event) {
event.preventDefault();
stripe.createToken(card).then(function(result) {
if (result.error) {
// Inform the user if there was an error
var errorElement = document.getElementById('card-errors');
errorElement.textContent = result.error.message;
} else {
stripeTokenHandler(result.token);
}
});
});
// Send Stripe Token to Server
function stripeTokenHandler(token) {
// Insert the token ID into the form so it gets submitted to the server
var form = document.getElementById('stripe-payment-form');
// Add Stripe Token to hidden input
var hiddenInput = document.createElement('input');
hiddenInput.setAttribute('type', 'hidden');
hiddenInput.setAttribute('name', 'stripeToken');
hiddenInput.setAttribute('value', token.id);
form.appendChild(hiddenInput);
// Submit form
form.submit();
}
然而,奇怪的是它不是create_subscription.php
,而是register.php
。当URL正确时,为什么它会像这样?对于您的信息,如果它有用,在条带付款表单之前,用户确实以完全不同的形式输入个人详细信息,并使用jquery发送到register.php
。但我甚至不使用addEventListener()
,而是使用$(jquery).click()
。