Results 1 to 4 of 4

Thread: Mail form validation - not working with CGI script

  1. #1
    Join Date
    Jul 2005
    Location
    West Lothian, Scotland
    Posts
    37
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Mail form validation - not working with CGI script

    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>

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    It doesn't help that you've nested two forms and only closed one of them. I think you mean:
    Code:
    <form onsubmit="return formCheck(this);" name="formcheck" method="POST" action="http://greenplanetpr.co.uk/cgi-bin/mailer/mailer.cgi">
    Your code leaves quite a lot to be desired. Have you heard of CSS?
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Jul 2005
    Location
    West Lothian, Scotland
    Posts
    37
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default

    Thanks for the help, your suggestion fixed the problem - I could have done without the sarcasm though.

    I am not a professional web designer and all the code you saw was obtained elsewhere and not written by me - the top part obviously from Dynamic Drive and the mailform part from my web host who offer common web scripts.

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    I could have done without the sarcasm though.
    Just helping you improve your coding style
    I am not a professional web designer
    If you're creating pages, that makes you a web designer. Professional or no, you'd do well to at least read through the W3Schools HTML and CSS tutorials.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •