How to add CAPTCHA functionality

Philip Butler asked on July 25, 2014 16:52

I am trying to find how to add CAPTCHA functionality to a web part, however looking through the dev guides: https://kentico.atlassian.net/wiki/pages/viewpage.action?pageId=26313722

I can't see if there is somewhere in the CMS I have to enable or if this can only be added in the code (transformation) or somewhere else ?

Thanks for your help

Phil

Recent Answers


Joshua Adams answered on July 25, 2014 17:52

Which webpart are you trying to add this functionality onto?

0 votesVote for this answer Mark as a Correct answer

Philip Butler answered on July 25, 2014 18:03

Hi Joshua

it's a content webpart we have built for send to a friend functionaility. il Kind regards Ph

0 votesVote for this answer Mark as a Correct answer

Joshua Adams answered on July 25, 2014 18:15

Is it connected to a form or just a standalone webpart?

You should be able to use this same code and hook it into your webpart.

Look at this control for an example: <%@ Register Src="~/CMSFormControls/Captcha/SecurityCode.ascx" TagName="SecurityCode" TagPrefix="uc1" %> <uc1:SecurityCode ID="captchaElem" runat="server" />

And make a property on your webpart called DisplayCaptcha /// public bool DisplayCaptcha { get { return ValidationHelper.GetBoolean(GetValue("DisplayCaptcha"), false); }

    set
    {
        SetValue("DisplayCaptcha", value);
    }
}


Then add this code to the setup control method
captchaElem.Visible = DisplayCaptcha;
lblCaptcha.Visible = DisplayCaptcha;
            plcCaptcha.Visible = DisplayCaptcha;

            And add this to the submit function:
             // Check if captcha is required and verify captcha text
        if (DisplayCaptcha && !captchaElem.IsValid())
        {
            // Display error message if captcha text is not valid
            lblError.Visible = true;
            lblError.Text = GetString("Webparts_Membership_RegistrationForm.captchaError");
            return;
        }

        And that should be it...
0 votesVote for this answer Mark as a Correct answer

Philip Butler answered on July 25, 2014 18:18 (last edited on July 25, 2014 18:18)

Hi Joshua

Thanks for your feedback I will follow what you have suggested

the webpart does sit inside a form

once again thanks for your help

Kind regards Phil

0 votesVote for this answer Mark as a Correct answer

Joshua Adams answered on July 25, 2014 18:26

Don't thank me yet...hopefully it will work.

If not post your results and we can come up with a solution.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.