Required field(s) validation
http://www.dynamicdrive.com/dynamici...uiredcheck.htm
I have previously used this script successfully in conjunction with a FormMail.asp script but am now having problems getting it to work with a CGI mail form. The form is sent whether all required fields are completed or not, with no prompt to complete them. Is there some reason why it will not work with a CGI script? I have copied the HTML from the mailing page below and would appreciate any assistance.
-----------------------------------------------------------------------------------------------------
<script language="JavaScript">
<!--
/***********************************************
* Required field(s) validation v1.10- By NavSurf
* Visit Nav Surf at http://navsurf.com
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/
function formCheck(formobj){
// Enter name of mandatory fields
var fieldRequired = Array("Name", "Company", "Business_Type", "Telephone", "Email_Address");
// Enter field description to appear in the dialog box
var fieldDescription = Array("Your Name", "Company Name", "Type of Business", "Contact Telephone", "email Address");
// dialog message
var alertMsg = "Sorry, you must complete the following fields:\n";
var l_Msg = alertMsg.length;
for (var i = 0; i < fieldRequired.length; i++){
var obj = formobj.elements[fieldRequired[i]];
if (obj){
switch(obj.type){
case "select-one":
if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
alertMsg += " - " + fieldDescription[i] + "\n";
}
break;
case "select-multiple":
if (obj.selectedIndex == -1){
alertMsg += " - " + fieldDescription[i] + "\n";
}
break;
case "text":
case "textarea":
if (obj.value == "" || obj.value == null){
alertMsg += " - " + fieldDescription[i] + "\n";
}
break;
default:
}
if (obj.type == undefined){
var blnchecked = false;
for (var j = 0; j < obj.length; j++){
if (obj[j].checked){
blnchecked = true;
}
}
if (!blnchecked){
alertMsg += " - " + fieldDescription[i] + "\n";
}
}
}
}
if (alertMsg.length == l_Msg){
return true;
}else{
alert(alertMsg);
return false;
}
}
// -->
</script>
<form method="POST" action="http://greenplanetpr.co.uk/cgi-bin/mailer/mailer.cgi">
<form name="formcheck" onsubmit="return formCheck(this);">
<input type="hidden" name="Redirect" value="http://greenplanetpr.co.uk/thanks.htm">
<input type="hidden" name="To" value="robert@greenplanetpr.co.uk">
<p><small><font face="Verdana">Your name:<font color="#FF0000">*</font><br>
<input type="text" name="Name" size="35" tabindex="1">
</font></small></p>
<p><font face="Verdana" style="font-size: smaller">Company </font><small>
<font face="Verdana">name:<font color="#FF0000">*</font><br>
<input type="text" name="Company" size="35" tabindex="2">
</font></small></p>
<p><font face="Verdana" style="font-size: smaller">Type of business</font><small><font face="Verdana">:<font color="#FF0000">*</font><br>
<input type="text" name="Business_Type" size="40" tabindex="3">
</font></small></p>
<p><font face="Verdana" style="font-size: smaller">Contact Telephone</font><small><font face="Verdana">:<font color="#FF0000">*</font><br>
<input type="text" name="Telephone" size="24" tabindex="4">
</font></small></p><p><small><font face="Verdana">Your email address:<font color="#FF0000">*</font><br>
<input type="text" name="EMail_Address" size="35" tabindex="5">
<br><br>Your message:<br>
<textarea rows="7" name="Message" cols="40" tabindex="6"></textarea>
<br><br>
<input type="submit" value="Send message">
</font></small></p>
</form>



Reply With Quote


Bookmarks