我到处寻找答案,我真的不知道我做错了什么。我意识到这可能是一个愚蠢的错误,但我绝对为此绞尽脑汁。
我有一个提交到 PHP 文件的脚本。发送时的脚本应该验证以确保填写了必填字段,如果没有填写,它应该弹出一个 Javascript 框,基本上告诉他们他们没有填写正确的字段。不幸的是,此刻,它只是发送。
代码如下:
<div id="formcontainer">
<div class="formcontent">
<h3>Fields marked (*) are required</h3>The amount of money that Affecting Real Change is able to raise is dependent on the generosity of donors and our volunteer's fantastic fundraising. All of the money raised goes towards project building materials. Without these funds we really wouldn't be able to do what we do.
</div>
<form method=post enctype=multipart/form-data action=formurl.php onSubmit="return validatePage1();">
<h3>Full Name (Insert as it appears on your passport) *</h3><p class="formfield"><input class=mainForm type=text name=field_1 id=field_1 size='40' value=''></p>
<h3>Your gender *</h3><select class=mainForm name=field_7 id=field_7><option value=''></option><option value="Male">Male</option><option value="Female">Female</option></select>
<h3>Email Address *</h3><p class="formfield"><input class=mainForm type=email name=field_2 id=field_2 size=40 value=""></p>
<h3>Phone Number *</h3><p class="formfield"><input class=mainForm type=text name=field_11 id=field_11 size='40' value=''></p>
<h3>Indicate Trip & Date *</h3><p class="formfield"><input class=mainForm type=text name=field_3 id=field_3 size='40' value=''></p>
<h3>Please type any more info here *</h3><textarea class=message name=field_5 id=field_5 rows=7 cols=40></textarea>
<h3>I have read your <a href="http://www.affectingrealchange.org/terms-and-conditions/" target="_blank">Terms and Conditions</a> and agree *</h3><select class=mainForm name=field_10 id=field_10><option value=''></option><option value="Yes">Yes</option><option value="No">No</option></select>
<!-- end of this page -->
<!-- page validation -->
<SCRIPT type=text/javascript>
function validatePage1()
{
retVal = true;
if (validateField('field_1','fieldBox_1','text',1) == false)
retVal=false;
if (validateField('field_2','fieldBox_2','email',1) == false)
retVal=false;
if (validateField('field_3','fieldBox_3','textarea',1) == false)
retVal=false;
if (validateField('field_5','fieldBox_5','textarea',1) == false)
retVal=false;
if (validateField('field_7','fieldBox_7','menu',1) == false)
retVal=false;
if (validateField('field_10','fieldBox_10','menu',1) == false)
retVal=false;
if (validateField('field_11','fieldBox_10','menu',1) == false)
retVal=false;
if(retVal == false)
{
alert('Please correct the errors. Fields marked with an asterisk (*) are required');
return false;
}
return retVal;
}
</SCRIPT>
<!-- end page validaton -->
<li class="mainForm">
<br/><p class="submit"><input id="saveForm" class="submit" type="submit" value="Submit" /></p>
</li>
</form>
我意识到这可能是一件非常愚蠢的事情,但我终其一生都无法弄清楚它是什么。
实际上,表单只需要验证一个字段。它正在使用的网站收到大量空白页提交,因此只需验证一个字段就可以了。
任何帮助都会很棒!
谢谢刘易斯