我需要在我使用Stripe付款网关重复付款的地方验证表格。我的代码在下面。
<form method="post" action="charge.php" name="renew" onsubmit="return validate();">
<input type="radio" name="package" id="package" mode="normal" duration="30" text="1 Monat" value="29.90"> 29.90 € Pro Werbeanzeige-Laufzeit: 1 Monat<br>
<input type="radio" name="package" id="package" mode="normal" duration="60" text="2 Monate" value="49.90"> 49.90 € Pro Werbeanzeige-Laufzeit: 2 Monate<br>
<input type="radio" name="package" id="package" mode="normal" duration="90" text="3 Monate" value="59.90"> 59.90 € Pro Werbeanzeige-Laufzeit: 3 Monate<br>
<input type="radio" name="package" id="package" mode="recurring" duration="30" text="Monate" value="19.90"> 19,90 € Monate<br>
<input name="oid" type="hidden" value="<?=$oid;?>" />
<input name="mode" id="mode" type="hidden" value="" />
<input name="duration" id="duration" type="hidden" value="" />
<!--<input type="submit" name="makepayment" value="Pay" > -->
<script src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key="<?php echo $stripe['publishable_key']; ?>"
data-name="GOALSTART"
data-description="1 Monate"
data-panel-label="Abonnieren"
data-label="PAY NOW"
data-locale="auto">></script>
</form>
<script type="text/javascript">
function validate(){
console.log('hello');
if (document.getElementById('package').checked) {
//alert("checked submit form");
return true;
} else {
alert("Unchecked form will not be submitted");
return false;
}
}
</script>
如果没有选中单选按钮,则在这里我将不提交表单。但是根据我的代码,它无法检查验证。
答案 0 :(得分:1)
在checkout.stripe.com脚本周围添加一个div。由于“立即付款”是动态生成的,因此您对其没有太多控制。因此,您可以通过以下方法限制对其的点击。
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
</head>
<body>
<form method="post" action="charge.php" name="renew" onsubmit="validate();">
<input type="radio" name="package" id="package-1" mode="normal" duration="30" text="1 Monat" value="29.90" required="true"> 29.90 € Pro Werbeanzeige-Laufzeit: 1 Monat<br>
<input type="radio" name="package" id="package-2" mode="normal" duration="60" text="2 Monate" value="49.90"> 49.90 € Pro Werbeanzeige-Laufzeit: 2 Monate<br>
<input type="radio" name="package" id="package-3" mode="normal" duration="90" text="3 Monate" value="59.90"> 59.90 € Pro Werbeanzeige-Laufzeit: 3 Monate<br>
<input type="radio" name="package" id="package-4" mode="recurring" duration="30" text="Monate" value="19.90"> 19,90 € Monate<br>
<input name="oid" type="hidden" value="<?=$oid;?>" />
<input name="mode" id="mode" type="hidden" value="" />
<input name="duration" id="duration" type="hidden" value="" />
<!--<input type="submit" name="makepayment" value="Pay" > -->
<div class="checkout-part-wrapper">
<script src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key="<?php echo $stripe['publishable_key']; ?>"
data-name="GOALSTART"
data-description="1 Monate"
data-panel-label="Abonnieren"
data-label="PAY NOW"
data-locale="auto">>
</script>
</div>
</form>
<script type="text/javascript">
jQuery('.checkout-part-wrapper').css('pointer-events', 'none');
jQuery('input[type=radio][name=package]').change(function() {
jQuery('.checkout-part-wrapper').css('pointer-events', 'auto');
});
</script>
</body>
</html>
答案 1 :(得分:0)
更改此行
if (document.getElementById('package').checked) {
到
if (document.querySelectorAll('input[name=package]:checked').length) {