Captcha images are very helpful in preventing spammers posting form data into our applications . A captcha image is a image having some distorted text which humans can read but not computer programs. It is a type of test that essures that the response is generated by a person.
In coldfusion captcha images can be easily generated using the <cfimage> tag. This tag is used to perform common image mnipulation operations. To generate captcha image, we just need to provide certain attributes to this tag like action = “captcha”, height = “number of pixel”, text = “text string” width = “number of pixel” and all these are required attribute.
Lets see a example
<form action="" method="post" >
<td>Enter Text Below:</td>
<td><input type="text" name="captcha"></td>
<cfimage action="captcha" text="hello" width="300" height="75" difficulty ="low">
<td><input type="submit" name="send" value="Submit"></td>
This simple code will generate the captcha image. Many times it happens that the image generated is not easily readable. So we need to refresh our captcha image or else we enter wrong text and submit the form to regenerate the image and continue the process till we get a wel readable text.
So as a solution to it we can refresh the captcha image using few lines of jQuery code which goes as below :
// loads the captchaDiv of refreshCaptcha.cfm page
And a slight modification in the above code to provide a link to refresh image:
<cfimage action="captcha" text="hello" width="300" height="75" difficulty ="high">
Can't read? <a href="" id="reloadLink">Reload</a>