Php 如何使用多个表单验证复选框?
我有3张表格和一个复选框,如下所示:Php 如何使用多个表单验证复选框?,php,javascript,forms,validation,Php,Javascript,Forms,Validation,我有3张表格和一个复选框,如下所示: <input type="checkbox" name="confirm_agreement" value=yes <?php if (isset($_POST["confirm_agreement2"])) {print "checked";}?>>I agree <form action="https://www.paypal.com/webscr" method="post"> <input ty
<input type="checkbox" name="confirm_agreement" value=yes <?php if (isset($_POST["confirm_agreement2"])) {print "checked";}?>>I agree
<form action="https://www.paypal.com/webscr" method="post">
<input type="image" src="https://www.paypal.com/en_US/x-click-but02.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
<input type="hidden" name="cmd" value="_xclick-subscriptions">
<input type="hidden" name="business" value="paypal@exploretalent.com">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="no_note2" value="1">
...
<input type="hidden" name="sra" value="1">
</form>
<form action="https://www.paypal.com/webscr" method="post">
<input type="image" src="https://www.paypal.com/en_US/x-click-but02.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
<input type="hidden" name="cmd" value="_xclick-subscriptions">
<input type="hidden" name="business" value="paypal@exploretalent.com">
<input type="hidden" name="no_shipping" value="2">
<input type="hidden" name="no_note2" value="2">
...
<input type="hidden" name="sra" value="2">
</form>
<form action="https://www.paypal.com/webscr" method="post">
<input type="image" src="https://www.paypal.com/en_US/x-click-but02.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
<input type="hidden" name="cmd" value="_xclick-subscriptions">
<input type="hidden" name="business" value="paypal@exploretalent.com">
<input type="hidden" name="no_shipping" value="2">
<input type="hidden" name="no_note2" value="2">
...
<input type="hidden" name="sra" value="2">
</form>
然后在表单上添加onsubmit=“return checkbox();”
,但这不起作用
关于如何做到这一点有什么想法吗
谢谢你也可以这样做
function checkCheckBoxes() {
if (document.getElementsByName('confirm_agreement')[0].checked == false)
{
alert ('You must agree with the User Agreement Terms!');
return false;
}
}
这是一行截取的jQuery,类似于
$('form').submit(函数(){if(!$('confirm#u agreement').is('checked')){alert('You must check the box');return false})你有没有理由不使用jQuery或其他JS库来让你的生活变得非常简单?
function checkCheckBoxes() {
if (document.getElementsByName('confirm_agreement')[0].checked == false)
{
alert ('You must agree with the User Agreement Terms!');
return false;
}
}