我不是 JavaScript 编码员,但从这个链接复制了一些 js 并尝试在我的表单中使用,但没有成功。可能是基本设置,例如onclick
这是不对的。只是猜测,因为我必须自己添加。我也在使用 Tectite 的 formmail,它正在验证表单。该网站是 Tectite.com。任何帮助表示赞赏!
这是代码:
// Checking to make sure email field is on the form
function validatecompare() {
if (typeof f.email2 != "undefined") {
if ((f.email2.value != f.email1.value) && (f.sameAsShip.checked)) {
customAlert("email2", bnadd_msg_005);
if ((typeof TeaLeaf != "undefined") && (typeof TeaLeaf.Client != "undefined") && (typeof TeaLeaf.Client.tlAddEvent != "undefined")) {
var nVO = {
ErrorMessage: bnadd_msg_018
}
TeaLeaf.Event.tlAddCustomEvent(subtype, nVO);
}
return false;
}
//Validate that email address has @ and .
if (f.email2 && (f.email2.value != f.email1.value) && (!editEmail(f.email2.value, 'Email Address'))) {
return false;
}
if (addrType == atBill) {
if (f.email2.value != f.email1.value) {
customAlert("email2", bnadd_msg_005);
if ((typeof TeaLeaf != "undefined") && (typeof TeaLeaf.Client != "undefined") && (typeof TeaLeaf.Client.tlAddEvent != "undefined")) {
var nVO = {
ErrorMessage: bnadd_msg_005
}
TeaLeaf.Event.tlAddCustomEvent(subtype, nVO);
}
return false;
} else {
if (f.email2 && (f.email2.value != f.email1.value) && (!editEmail(f.email1.value, 'Email Address'))) {
return false;
} else return true;
}
}
}
break;
}
这是我的表格:
<form action="/formmail/formmail.php" onsubmit="return validatecompare()" method="post" enctype="multipart/form-data" name="ContactForm" id="ContactForm">
<input type="hidden" name="env_report" value="REMOTE_HOST,REMOTE_ADDR,HTTP_USER_AGENT,AUTH_TYPE,REMOTE_USER" />
<!-- STEP 2: Put your email address in the 'recipients' value.
Note that you also have to allow this email address in the
$TARGET_EMAIL setting within formmail.php!
-->
<input type="hidden" name="recipients" value="sales_*_comtechnorthamerica.com" />
<!-- STEP 3: Specify required fields in the 'required' value - or leave unchanged.
NOTE: DO NOT put your email address and name here.
"Your email address" and "Your name" are error messages for your users to see,
not placeholders for you to replace.
-->
<input type="hidden" name="required" value="FullName:-Your name,Title:-Your title,Company:-Your company,Website:-Your website,Address:-Your address,Telephone:-Your telephone,email1:-Your email address,email2:-Your Confirm email address" />
<!-- STEP 4: Put your subject line in the 'subject' value. -->
<input type="hidden" name="subject" value="Comtech Contact Form Submission Testing" />
<!-- ALL DONE! Visit our site for HOW TO guides and more complex features. -->
<!-- this derives (creates) "email" and "realname" special fields from the input fields -->
<input type="hidden" name="derive_fields" value="email=email,realname=FullName" />
<!-- this excludes the "email" and "realname" special fields from the body of the email you receive -->
<!-- <input type="hidden" name="mail_options" value="Exclude=email;realname" /> -->
<input type="hidden" name="good_url" value="http://www.comtechnorthamerica.com/thankYou.php" />
<table width="380" border="0" cellspacing="0" cellpadding="6">
<tr>
<td valign="top" class="layoutFormBox"><h1>Information Request Form</h1>
<table width="360" border="0" align="center" cellpadding="4" cellspacing="0">
<tr>
<td><div align="right">
<input type="checkbox" name="Send_product_literature" id="Send_product_literature" value="Yes" />
</div></td>
<td><div align="left"> Send product literature</div></td>
</tr>
<tr>
<td><div align="right">
<input type="checkbox" name="Have_a_salesperson_contact_me" id="Have_a_salesperson_contact_me" value="Yes" />
</div></td>
<td><div align="left"> Have a salesperson contact me</div></td>
</tr>
</table>
<br />
<table width="360" border="0" align="center" cellpadding="6" cellspacing="0">
<tr>
<td width="335" valign="top"> </td>
<td valign="top"><div class="required" align="left">* denotes required field</div></td>
</tr>
<tr>
<td width="70" valign="top"><div align="right">Name:<span class="required">*</span></div></td>
<td width="335" valign="top"><div align="left">
<input type="text" name="FullName" id="FullName" />
</div></td>
</tr>
<tr>
<td valign="top"><div align="right">Title:<span class="required">*</span></div></td>
<td valign="top"><div align="left">
<input type="text" name="Title" id="Title" />
</div></td>
</tr>
<tr>
<td valign="top"><div align="right">Company:<span class="required">*</span></div></td>
<td valign="top"><div align="left">
<input type="text" name="Company" id="Company" />
</div></td>
</tr>
<tr>
<td valign="top"><div align="right">Website:<span class="required">*</span></div></td>
<td valign="top"><div align="left">
<input type="text" name="Website" id="Website" />
</div></td>
</tr>
<tr>
<td valign="top"><div align="right">Address:<span class="required">*</span></div></td>
<td valign="top"><div align="left">
<textarea name="Address" rows="4" id="Address"></textarea>
</div></td>
</tr>
<tr>
<td valign="top"><div align="right">Telephone:<span class="required">*</span></div></td>
<td valign="top"><div align="left">
<input type="text" name="Telephone" id="Telephone" />
</div></td>
</tr>
<tr>
<td valign="top"><div align="right">Cell Phone:</div></td>
<td valign="top"><div align="left">
<input type="text" name="Cell" id="Cell" />
</div></td>
</tr>
<tr>
<td valign="top"><div align="right">Fax:</div></td>
<td valign="top"><div align="left">
<input type="text" name="Fax" id="Fax" />
</div></td>
</tr>
<tr>
<td valign="top"><div align="right">Email:<span class="required">*</span></div></td>
<td valign="top"><div align="left">
<input type="text" name="email1" id="email1" />
</div></td>
</tr>
<tr>
<td valign="top"><div align="right">Confirm Email:<span class="required">*</span></div></td>
<td valign="top"><div align="left">
<input type="text" name="email2" id="email2" />
</div></td>
</tr>
<tr>
<td valign="top"><div align="right">Primary Interest:</div></td>
<td valign="top"><div align="left">
<select name="Primary_Interest" id="Primary_Interest">
<option>In-line spring coiling, testing, spring detangling systems</option>
<option>Laser marking systems</option>
<option>Feeder bowl technology</option>
<option>Drum technology for spring & parts handling / feeding</option>
</select>
</div></td>
</tr>
<tr>
<td valign="top"><div align="right">Comments:</div></td>
<td valign="top"><div align="left">
<textarea name="Comments" rows="6" id="Comments"></textarea>
</div></td>
</tr>
<tr>
<td colspan="2" valign="top"><div align="left">How did you hear about Comtech?</div></td>
</tr>
<tr>
<td valign="top"><div align="right"></div></td>
<td valign="top"><div align="left">
<select name="How_did_you_hear_about_Comtech" id="How_did_you_hear_about_Comtech">
<option>Google Search</option>
<option>Direct Mailing</option>
<option>Thomas Register</option>
<option>Trade Magazine</option>
<option>Tradeshow</option>
<option>Comtech Literature</option>
<option>Sales Representative</option>
<option>Customer Referral</option>
<option selected="selected">Please Select</option>
</select>
</div></td>
</tr>
<tr>
<td height="37" valign="top"> </td>
<td valign="top"><input type="submit" onclick="validatecompare()" value="Submit" /></td>
</tr>
</table>
</form>