EasyCFM.COM ColdFusion Forums / Good Coding Tips! / JS/CF CAPTCHA system

   Reply to Discussion | New Discussion << previous || next >> 
Posted By Discussion Topic: JS/CF CAPTCHA system -- page: 1 2

book mark this topic Printer-friendly Version  send this discussion to a friend  new posts last

nicky2k
03-06-2009 @ 4:42 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
New Member
Posts: 35
Joined: Jan 2004

Not a stupid question at all.

Underneath the CAPTCHA, write this:
<input type="hidden" name="captcha_string" value="#captcha_string#">
<input type="text" name="captcha_text" size="25" />
The first input passes the actual string generated by the image to the action page. The second string passes what the user enters to the action page.

In your action page, do something like this:
<cfif form.captcha_text neq form.captcha_string>
<p>The text entered does not match the image. Please try again.</p>
</cfif>

Here, you are comparing the generated CATCHPA to what the user has entered.

Of course, you need to modify this according to your own form.

Hope this helps.

MIGhunter
03-06-2009 @ 6:04 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Senior Member
Posts: 570
Joined: Apr 2006

ok, so what about this.  The form I am using posts to itself.  So, how do I add the cfif stuff

<cfif form.captcha_text neq form.captcha_string>
<p>The text entered does not match the image. Please try again.</p>
</cfif>

Here is my page:

<cfscript>  
function RandomString(CharList,Length)
{
   tmpRndStr="";
   for (i=1; i LE Length; i=i+1)
        tmpRndStr=tmpRndStr &   Mid(CharList,Rand()*Len(CharList)+1,1);
return tmpRndStr;
}
</cfscript>

<CFIF IsDefined("process")>
     If the process field has a value of One, then do the following:
    <!--- Send the message to yourself, when the user posts it on your site. --->
    <CFMAIL to="" from="#ContactEmail#" Subject="Contact From YourSite.Com">
        #ContactMessage#

        Message By: #ContactName# - #ContactEmail#
        ========================================
    </CFMAIL>
    <!--- Send one to the person writing, thanking them and reminding them what they wrote. --->
    <CFMAIL to="#ContactEmail#" from="From Email" Subject="The Subject!">

    Thank you for your message,
       We'll be in touch as soon as we can, we receive hundred and thousands
    of emails a day; so we might take a while, but we'll reply!

    Thanks again for visiting our site,
    Yourname - Webmaster
    Webmaster@Yoursite.Com

    You wrote:
    #ContactMessage#

    Message By: #ContactName# - #ContactEmail#
    ========================================
    </CFMAIL>

    Thanks for your message!

    <!--- If "Process" is not defined, let's show the form: --->
<CFELSE>

    <cfform action="contact.cfm" method="post">
    <input type="hidden" name="Process" Value="1">
    <table align="center" border="0" width="100%">
        <tr>
            <td width="40%" valign="top" align="right">Name:</td>
            <td width="60%"><cfinput type="text" name="ContactName" size="20" required="yes" message="Please Enter Your Name!"></td>
        </tr>
        <tr>
            <td width="40%" valign="top" align="right">Email:</td>
            <td width="60%"><cfinput type="text" name="ContactEmail" size="20" required="yes" message="Please Enter Your Email Address!"></td>
        </tr>
        <tr>
            <td width="40%" valign="top" align="right">Message:</td>
            <td width="60%"><textarea rows="4" name="ContactMessage" cols="20"></textarea></td>
        </tr>
          <tr>
               <td width="40%" valign="top" align="right"></td>
               <td width="60%"><cfset captcha_string=RandomString("ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890",6)>
               <cfimage action="captcha" text="#captcha_string#" fontsize="24" difficulty="low" width="200" height="37" /></td>
          </tr>
        <tr>
            <td width="40%" valign="top" align="right">Enter the Text as shown:</td>
            <td width="60%"><input type="hidden" name="captcha_string" value="#captcha_string#"><input type="text" name="captcha_text" size="25" /> </td>
        </tr>               
        <tr>
            <td width="40%" valign="top" align="right"></td>
            <td width="60%"><input type="submit" value="Submit Contact Form"></td>
        </tr>               
    </table>
    </cfform>

</CFIF>


This message was edited by MIGhunter on 3-6-09 @ 6:06 AM

nicky2k
03-06-2009 @ 6:13 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
New Member
Posts: 35
Joined: Jan 2004

What I tend to do is something like this:

<cfif isdefined("form.process")>
   <!--- Do validation bits --->
   <cfif form.captcha_text neq form.captcha_string>
    <p>The text entered does not match the image. Please try again.</p>
   <cfelse>
   <!--- validation passed --->
   <!--- Send the message to yourself, when the user posts it on your site. --->
    <CFMAIL to="" from="#ContactEmail#" Subject="Contact From YourSite.Com">
        #ContactMessage#

        Message By: #ContactName# - #ContactEmail#
        ========================================
    </CFMAIL>
    <!--- Send one to the person writing, thanking them and reminding them what they wrote. --->
    <CFMAIL to="#ContactEmail#" from="From Email" Subject="The Subject!">

    Thank you for your message,
       We'll be in touch as soon as we can, we receive hundred and thousands
    of emails a day; so we might take a while, but we'll reply!

    Thanks again for visiting our site,
    Yourname - Webmaster
    Webmaster@Yoursite.Com

    You wrote:
    #ContactMessage#

    Message By: #ContactName# - #ContactEmail#
    ========================================
    </CFMAIL>

    Thanks for your message!
   </cfif>
<cfelse>

<cfform action="contact.cfm" method="post">
    <input type="hidden" name="Process" Value="1">
    <table align="center" border="0" width="100%">
        <tr>
            <td width="40%" valign="top" align="right">Name:</td>
            <td width="60%"><cfinput type="text" name="ContactName" size="20" required="yes" message="Please Enter Your Name!"></td>
        </tr>
        <tr>
            <td width="40%" valign="top" align="right">Email:</td>
            <td width="60%"><cfinput type="text" name="ContactEmail" size="20" required="yes" message="Please Enter Your Email Address!"></td>
        </tr>
        <tr>
            <td width="40%" valign="top" align="right">Message:</td>
            <td width="60%"><textarea rows="4" name="ContactMessage" cols="20"></textarea></td>
        </tr>
          <tr>
               <td width="40%" valign="top" align="right"></td>
    
               <td width="60%"><cfset captcha_string=RandomString("ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890",6)>
               <cfimage action="captcha" text="#captcha_string#" fontsize="24" difficulty="low" width="200" height="37" /></td>
          </tr>
        <tr>
            <td width="40%" valign="top" align="right">Enter the Text as shown:</td>
            <td width="60%"><input type="hidden" name="captcha_string" value="#captcha_string#"><input type="text" name="captcha_text" size="25" /> </td>
        </tr>              
        <tr>
            <td width="40%" valign="top" align="right"></td>
            <td width="60%"><input type="submit" value="Submit Contact Form"></td>
        </tr>              
    </table>
    </cfform>


</cfif>



MIGhunter
03-06-2009 @ 11:12 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Senior Member
Posts: 570
Joined: Apr 2006

hmm, I put it all together and it keeps telling me that the stings don't match. http://migcfdesign.com/ContactForms/BotDContact/contact.cfm


<cfscript>  
function RandomString(CharList,Length)
{
   tmpRndStr="";
   for (i=1; i LE Length; i=i+1)
        tmpRndStr=tmpRndStr &   Mid(CharList,Rand()*Len(CharList)+1,1);
return tmpRndStr;
}
</cfscript>

<cfif isdefined("form.process")>
   <!--- Do validation bits --->
   <cfif form.captcha_text neq form.captcha_string>
    <p>The text entered does not match the image. Please try again.</p>
   <cfelse>
   <!--- validation passed --->
   <!--- Send the message to yourself, when the user posts it on your site. --->
    <CFMAIL to="" from="#ContactEmail#" Subject="Contact From YourSite.Com">
        #ContactMessage#

        Message By: #ContactName# - #ContactEmail#
        ========================================
    </CFMAIL>
    <!--- Send one to the person writing, thanking them and reminding them what they wrote. --->
    <CFMAIL to="#ContactEmail#" from="From Email" Subject="The Subject!">

    Thank you for your message,
       We'll be in touch as soon as we can, we receive hundred and thousands
    of emails a day; so we might take a while, but we'll reply!

    Thanks again for visiting our site,
    Yourname - Webmaster
    Webmaster@Yoursite.Com

    You wrote:
    #ContactMessage#

    Message By: #ContactName# - #ContactEmail#
    ========================================
    </CFMAIL>

    Thanks for your message!
   </cfif>
<cfelse>

<cfform action="contact.cfm" method="post">
    <input type="hidden" name="Process" Value="1">
    <table align="center" border="0" width="100%">
        <tr>
            <td width="40%" valign="top" align="right">Name:</td>
            <td width="60%"><cfinput type="text" name="ContactName" size="20" required="yes" message="Please Enter Your Name!"></td>
        </tr>
        <tr>
            <td width="40%" valign="top" align="right">Email:</td>
            <td width="60%"><cfinput type="text" name="ContactEmail" size="20" required="yes" message="Please Enter Your Email Address!"></td>
        </tr>
        <tr>
            <td width="40%" valign="top" align="right">Message:</td>
            <td width="60%"><textarea rows="4" name="ContactMessage" cols="20"></textarea></td>
        </tr>
          <tr>
               <td width="40%" valign="top" align="right"></td>
    
               <td width="60%"><cfset captcha_string=RandomString("ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890",6)>
               <cfimage action="captcha" text="#captcha_string#" fontsize="24" difficulty="low" width="200" height="37" /></td>
          </tr>
        <tr>
            <td width="40%" valign="top" align="right">Enter the Text as shown:</td>
            <td width="60%"><input type="hidden" name="captcha_string" value="#captcha_string#"><input type="text" name="captcha_text" size="25" /> </td>
        </tr>              
        <tr>
            <td width="40%" valign="top" align="right"></td>
            <td width="60%"><input type="submit" value="Submit Contact Form"></td>
        </tr>              
    </table>
    </cfform>


</cfif>


nicky2k
03-06-2009 @ 11:14 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
New Member
Posts: 35
Joined: Jan 2004

Put a <cfdmp var ="#form#"> after the form submission to see what it passes.

nicky2k
03-06-2009 @ 11:31 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
New Member
Posts: 35
Joined: Jan 2004

That should be <cfdump> not <cfdmp>.

MIGhunter
03-07-2009 @ 1:33 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Senior Member
Posts: 570
Joined: Apr 2006

man, what a pain in the rump.  Had to contact fusionlink again cause when i tried to use cfdump I got: Security: The requested template has been denied access to createobject(java)

MIGhunter
03-07-2009 @ 2:55 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Senior Member
Posts: 570
Joined: Apr 2006

ok, here is what I have:


struct
CAPTCHA_STRING      #captcha_string#
CAPTCHA_TEXT      G3TUMR
CONTACTEMAIL      
CONTACTMESSAGE      Hi
CONTACTNAME      Mike
FIELDNAMES      PROCESS,CONTACTNAME,CONTACTEMAIL,CONTACTMESSAGE,CAPTCHA_STRING,CAPTCHA_TEXT
PROCESS      1


This message was edited by MIGhunter on 3-7-09 @ 5:34 AM

MIGhunter
03-07-2009 @ 3:07 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Senior Member
Posts: 570
Joined: Apr 2006

fixed it, didn't have any cfoutput to process the captcha_string

PAGE: 1 2

Website Designed and Developed by Pablo Varando.