Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Josh Blade 7 posts 27 karma points
    Sep 17, 2010 @ 00:44
    Josh Blade
    0

    Recaptcha

    I'm trying to add a recaptcha to the blogs on our website. Mainly I'm trying to figure out how to set up a reference to the Recaptcha.dll

    Can I do this through the umbraco login on a web browser? Someone else set up our Umbraco and I'm new to this trying to figure it out. I was told that our Visual Studio isn't controlling any part of the site which uses Umbraco, so this confuses me as everything I've seen on reCaptcha has you go through visual studio when using Umbraco.

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Sep 17, 2010 @ 03:43
    Lee Kelleher
    0

    Hi Josh,

    Coincidently, I have just added a reCAPTCHA to one of my client's Umbraco websites a few minutes ago.  You shouldn't need to open Visual Studio, but you will need to create a new .NET user-control to use it.

    Drop the Recaptcha.dll (and Recaptcha.pdb) into your /bin folder.

    On your form, you'll need to incorporate the following into the .NET user-control:

    <%@ Control Language="C#" %>
    <%@ Register TagPrefix="recaptcha" Namespace="Recaptcha" Assembly="Recaptcha" %>
    
    <script runat="server">
        protected void btnSubmit_Click(object sender, System.EventArgs e)
        {
            this.recaptcha.Validate();
    
            if (Page.IsValid && this.recaptcha.IsValid)
            {
                /* ... add whatever code you need here ... */
            }
            else
            {
                this.recaptcha.Focus();
            }
        }
    </script>
    
    <div>
        <recaptcha:RecaptchaControl ID="recaptcha" runat="server" Theme="white" Enabled="true" />
        <asp:Button runat="server" ID="btnSubmit" Text="Submit" OnClick="btnSubmit_Click" />
    </div>

    The documentation for the reCAPTCHA API doesn't mention that you need to call "Validate()" explicitly, but I had difficulty getting it to work without it!

    For the Public and Private keys, I added those directly to the appSettings in the Web.config:

    <appSettings>
        ...
        <!-- RECAPTCHA -->
        <add key="RecaptchaPublicKey" value="..." />
        <add key="RecaptchaPrivateKey" value="..." />
        <add key="RecaptchaSkipValidation" value="false" />
    </appSettings>

    Best of luck.

    Cheers, Lee.

  • Josh Blade 7 posts 27 karma points
    Sep 21, 2010 @ 00:57
    Josh Blade
    0

    Thanks for the help, Lee. I have another question if you get around to seeing this again.

    I'm getting the recaptcha widget to appear just fine, however I'm having trouble linking it to my submit button for validation.

    For posting comments, we have a user control which has the textboxes with some some validation and what not.

    I'm having trouble with the btnSubmit method you posted. It doesn't seem to do anything when the validation information from the recaptcha is correct (I tried just changing the text on some labels to verify).

    AmI missing something silly?

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Sep 21, 2010 @ 01:19
    Lee Kelleher
    0

    Hi Josh,

    Are you using a ValidationGroup on the other controls? If so, check that the submit button has it too.

    Other than that, its difficult to say without seeing the code (or a snippet).

    Cheers, Lee.

  • Josh Blade 7 posts 27 karma points
    Sep 22, 2010 @ 22:07
    Josh Blade
    0

    <%

    @ Control Language="C#" AutoEventWireup="true" CodeBehind="frmBlogComment.ascx.cs" Inherits="Umlaut.Umb.Blog.frmBlogComment" %>

    <%

    @ Register TagPrefix="recaptcha" Namespace="Recaptcha" Assembly="Recaptcha" %>

     

    <script runat="server">

     

     

    </script>

    <

     

    dl>

    <

     

    dt>Name: <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="This field is required" ControlToValidate="txtName" ValidationGroup="postcomment"></asp:RequiredFieldValidator></dt>

    <

     

    dd><asp:TextBox ID="txtName" runat="server"></asp:TextBox></dd>

    <

     

    dt>Email: <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="This field is required" ControlToValidate="txtEmail" ValidationGroup="postcomment"></asp:RequiredFieldValidator ></dt><dd><asp:TextBox ID="txtEmail" runat="server"></asp:TextBox></dd>

    <

     

    dt>Website: </dt><dd><asp:TextBox ID="txtWebsite" runat="server"></asp:TextBox></dd>

    <

     

    dt>Comment: <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ErrorMessage="This field is required" ControlToValidate="txtComment" ValidationGroup="postcomment"></asp:RequiredFieldValidator></dt>

    <

     

    dd>

    <

     

    asp:TextBox ID="txtComment" runat="server" TextMode="MultiLine"></asp:TextBox>

    </

     

    dd>

    <

     

    dt>&nbsp;</dt>

    <

     

    div>

     

     

    <recaptcha:RecaptchaControl

     

    ID="recaptcha"

     

    runat="server"

     

    PublicKey="I have the public key here"

     

    PrivateKey="I have the private key here"

     

    Theme="white"

     

    Enabled="true" />

     

    </

     

    div>

    <

     

    dd>

     

    <asp:Button runat="server" ID="btnSubmit" Text="Submit" OnClick="btnSubmit_Click" ValidationGroup = "postcomment"/>

    </

     

    dd>

    </

     

    dl>

    This is the user control that was already implemented. It's basically just 4 text boxes and a submit button (then the recaptcha widget I added).

    I'm really just not sure what to do with the 'insert code here' to tell it to actually submit.

    <script runat="server">

    protected void btnSubmit_Click(object sender, System.EventArgs e){

    this.recaptcha.Validate();

    if (Page.IsValid && this.recaptcha.IsValid){

    'insert code here'

     

    }

    else{

    this.recaptcha.Focus();

    }

    }

    Thanks again for your time, Lee.

  • Josh Blade 7 posts 27 karma points
    Sep 22, 2010 @ 22:09
    Josh Blade
    0

    And sorry for the terrible formatting on the code up above... I just copy pasted, and it looked fine when I submitted. I tried editting it to make it readable and it came out the same way again.

  • Josh Blade 7 posts 27 karma points
    Sep 25, 2010 @ 20:30
    Josh Blade
    0

    Thanks for all of your help Lee! I finally figured it out. I just needed to call btnSubmit_Click(sender,e) when the recaptcha was valid.

  • mfeola 117 posts 221 karma points
    Nov 12, 2010 @ 20:42
    mfeola
    0

    my blog uses the ajax comment form for its comments... i dont think this will work now?  or maybe there is a way to make the comments form use the old form instead of the ajax one?

  • aleksandar 14 posts 74 karma points
    Aug 27, 2015 @ 08:45
    aleksandar
    0

    having google recaptcha dll. file is making problems with dynamic, it doesn't show the images on my site, does anyone have that problem as well ?, and how do i resolve this !?

Please Sign in or register to post replies

Write your reply to:

Draft