PDA

View Full Version : Need email validation and captcha in same form



Elbee
05-22-2012, 12:45 PM
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



<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>





<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

ApacheTech
05-22-2012, 12:58 PM
There are a couple of mistakes in your HTML markup. Fixed below. See if that changes anything.



<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.