Results 1 to 2 of 2

Thread: Need email validation and captcha in same form

  1. #1
    Join Date
    Aug 2010
    Location
    Jacksonville, FL
    Posts
    85
    Thanks
    31
    Thanked 0 Times in 0 Posts

    Default Need email validation and captcha in same form

    Hello,

    When I have email validation and captcha in the same form, simply passing the captcha allows the form to be sent without an email address. When I remove the captcha, the form will not send without the email address. I want to have both. What am I missing?

    http://jaxpubliclibrary.org/lib/websiteform-test.html

    Code:
    <script>
    
    function validateForm()
    {
    var x=document.forms["WebsiteQuestion"]["Email"].value;
    var atpos=x.indexOf("@");
    var dotpos=x.lastIndexOf(".");
    if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length)
      {
      alert("Not a valid e-mail address");
      return false;
      }
    }
    
    function clearForms()
    {
      var i;
      for (i = 0; (i < document.forms.length); i++) {
        document.forms[i].reset();
      }
    }
    </script>

    Code:
     <div align="center">
     <script language="javascript" src="http://www.captcha.cc/cap.js?cap_k=tocsoLPahVjmEHJZWtenaJEDoJXfrQaa" type="text/javascript"></script>
    <input type=hidden name=cap_h id=cap_h value="">
    <img border=1 id=cap_i src="http://www.captcha.cc/img.cgi?cap_k=tocsoLPahVjmEHJZWtenaJEDoJXfrQaa" align=middle><img align=middle style="margin-left: 4px;" id=cap_r onload="return cap_showReload(event);" src="http://www.captcha.cc/blank.png"><br>
    <input id=cap_t name=cap_t type=text value="" style="margin-top:4px;">
    <input type=submit value="Submit Form" onclick="return cap_valid(event);">						
    </div>
    I appreciate any help. Thank you, Elbee

  2. #2
    Join Date
    Apr 2012
    Location
    Chester, Cheshire
    Posts
    329
    Thanks
    7
    Thanked 35 Times in 35 Posts

    Default

    There are a couple of mistakes in your HTML markup. Fixed below. See if that changes anything.

    Code:
    <div align="center">
    <script language="javascript" src="http://www.captcha.cc/cap.js?cap_k=tocsoLPahVjmEHJZWtenaJEDoJXfrQaa" type="text/javascript"></script>
    <input type="hidden" name="cap_h" id="cap_h" value="">
    <img border="1" id="cap_i" src="http://www.captcha.cc/img.cgi?cap_k=tocsoLPahVjmEHJZWtenaJEDoJXfrQaa" align="middle"><img align="middle" style="margin-left: 4px;" id=cap_r onload="return cap_showReload(event);" src="http://www.captcha.cc/blank.png"><br>
    <input id="cap_t" name="cap_t" type="text" value="" style="margin-top:4px;">
    <input type="submit" value="Submit Form" onclick="return cap_valid(event);">						
    </div>
    Not that it will change much, but you're also using a fair amount of depreciated code. You should strip out any "align", "border" etc and replace with a CssClass.

  3. The Following User Says Thank You to ApacheTech For This Useful Post:

    Elbee (05-22-2012)

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
  •