PDA

View Full Version : Captcha Overrides Email Validation



Elbee
06-08-2012, 04:55 PM
Hello,

Without the captcha, the form validates that there is an email address present. With the captcha, it allows the form to be submitted without an email address.
http://jaxpubliclibrary.org/lib/websiteform-test.html

[CODE]
<head>
<script>
function validateForm()
{
var x=document.forms["WebsiteQuestion"]["Email"].value;
var atpos=x.indexOf("@");
var dotpos=x.lastIndexOf(".");
if (!(/^([a-z0-9])([\w\.\-\+])+([a-z0-9])\@((\w)([\w\-]?)+\.)+([a-z]{2,4})$/i.test(x))) // returns true if invalid

{
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>
</head>


<body>

<div id="websitequestion">
<form action="websiteformhandler-test.asp" method="post" name="WebsiteQuestion" id="WebsiteQuestion" onsubmit="return validateForm()">
<input type="hidden" name="department" value="WebsiteQuestion" />


<h1><span>Ask a Question About This Website</span></h1>

<p>Please use this form to submit questions or comments about this website. Complete the form below then click &quot;Submit.&quot; </p>

<label>Would you like a reply?</label>
<input type="radio" name="Reply" value="Yes" checked="checked" />
Yes
<input type="radio" name="Reply" value="No" />
No

<p>&nbsp;</p>

<div class="webform">

<p class="break"></p>

<label>Name:</label>
<div class="left"><input type="text" class="blue_form_box" name="SubmittedBy" maxlength="75" size="50" />
</div>

<p style="clear:both"></p>

<label>Library Card:</label>
<div class="left"><input type="text" class="blue_form_box" name="LibCd" maxlength="75" size="50" />
</div>

<p style="clear:both"></p>

<label>Street Address:</label>
<div class="left"><input type="text" class="blue_form_box"name="Address" maxlength="75" size="50" />
</div>

<p style="clear:both"></p>

<label>City/State:</label>
<div class="left"><input type="text" class="blue_form_box" name="city" maxlength="50" size="25" />
</div>

<p style="clear:both"></p>

<label>Zip Code:</label>
<div class="left"><input type="text" class="blue_form_box" name="zip" maxlength="10" size="11" />
</div>

<p style="clear:both"></p>

<label>E-Mail Address:</label>
<div class="left"><input type="text" class="blue_form_box" name="Email" maxlength="75" size="50" /><br />
<span class="red">*Required</span>
</div>

<p style="clear:both"></p>

<label>Question:</label>
<div class="left"><textarea class="blue_form_box" name="SuggestionText" rows="3" cols="50"></textarea></div>

<p style="clear:both"></p>


</div>


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


</form>
</div>

</body>

I appreciate any help. Thank you, Elbee