![]()
I recently had a project where my customer was getting alot of spam thru a contact form. So I thought I could use some CAPTCHA on the web form to stop some spam. I knew CF8 had the functionality to create CAPTCHA images, but I didn't know how to actually implement it. So after a bit of googling, I found Ben Nadel's post on creating and validating CAPTCHA images on forms.
I will briefly go over his code and show you my final result...
First step is to create the CAPTCHA phrase:
What is happening above is I am putting all the letters and numbers I want available to my CAPTCHA image into an array called arrValidChars. Then I am shuffling the characters and selecting the first 4 characters in the array I just created. I am then encrypting my newly created CAPTCHA phrase so I can pass it over in a hidden form field for processing.
Next step, create the form:
Once the user hits the submit button, the form data is passed to the page again and the processing begins:
<!--- Process form --->
<!--- CAPTCHA doesn't match, throw error --->
I first decrypt the captcha_check phrase and check if it matches what the user submitted. If it doesn't, I throw an error!
So all my code looks like this:
<!--- Process form --->
<!--- CAPTCHA doesn't match, throw error --->
Thanks Ben!
Recent Comments