Created
October 8, 2013 17:15
-
-
Save jchudzynski/6888096 to your computer and use it in GitHub Desktop.
Instructions for using captcha
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. Copy ajax.cfc to your folder | |
2. Add the following code to the file's header. | |
<cfajaxproxy cfc="atcdev.applications.captcha.ajax" jsclassname="proxy" /> | |
<cfinvoke component="ajax" returnvariable="captcha" method="makeRandomString"> | |
<cfset captchaHash = hash(captcha)> | |
<script type="text/javascript"> | |
<!-- | |
<cfoutput> | |
var #toScript(captchaHash, "captchaHash")#; | |
</cfoutput> | |
function testCaptcha() | |
{ | |
var p = new proxy(); | |
p.setSyncMode(); | |
var doc = document.getElementById("cap").value; | |
var hash = p.getHash(doc); | |
if(hash === captchaHash){ | |
document.getElementById("cap").style.backgroundColor ="White"; | |
return true; | |
} | |
document.getElementById("cap").style.backgroundColor ="Yellow"; | |
return false; | |
} | |
</script> | |
A default AJAX cfc file is stored in ATCDEV/Applications/Captcha/ folder | |
If you want to have a local ajax.cfc. Make sure that your replace path in bold with your path to the ajax.cfc. | |
For example path to the ajax.cfc in CDE/form/test would be cde.form.test.ajax. | |
3. Add following html element to the body of your file between <form> </form> tags. | |
<table cellspacing="0" cellpadding="4" border="0"> | |
<tbody> | |
<tr bgcolor="#003399"> | |
<td align="left"><div align="left"><small><font color="#ffffff" size="2" face="Arial"><p>Type characters from the image below <cfoutput><input type="hidden" name="captchaHash" value="#captchaHash#"/> <input id="cap" type="text" /> </cfoutput></p></font></small></div></td> | |
</tr><tr><td> | |
<cfimage action="captcha" width="300" height="75" text="#captcha#"> | |
</td></tr></tbody> | |
</table> | |
4. Make sure that your form element contains onsubmit parameter. | |
<form action="WaiverFormConfirm.cfm" method="POST" name="WaiverForm" id="form1" onsubmit="return testCaptcha()"> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment