0
votes

I would like to install ReCaptcha to our Umbraco Version 7. But I can't seem to find the correct approach. Basically I want to add the captcha element inside my custom form (not the Umbraco Form). Is there a way to do it? It seems the approach of adding the Recaptcha is not the same as how you add it in PHP application. How should I do this in Umbraco?

Update: Recaptcha version can either be version 1, 2 or 3

4
Which reCaptcha version? - Jannik Anker
It can either be version 1 2 or 3 as long as recaptcha will be added - MadzQuestioning

4 Answers

1
votes

reCaptcha V2 only requires a few simple lines of HTML to be inserted, AFAIK. You should be able to insert both a script tag and an HTML element anywhere inside your form element (inside Html.BeginForm if that's what you're doing) in your custom form, as long as you have an API key. I did this the other day and it just worked.

https://developers.google.com/recaptcha/docs/display

It doesn't need "installation", but it requires some fiddling with code.

1
votes

I wrote a post about it here a while back, https://www.jondjones.com/learn-umbraco-cms/umbraco-7-tutorials/umbraco-security/how-to-add-a-recapture-within-your-umbraco-website/

The quick option is to install recaptha mvc via Nuget and then decorate your controller with CaptchaValidator and use the Recaptcha in your HTML

0
votes

In your controller just check the form values and get the captcha value from it like this below, if that value is null then the person hasn't filled it otherwise it will have a value in it.

var formData = Request.Form;
var captchaRequest = formData["g-recaptcha-response"];
if (string.IsNullOrWhiteSpace(captchaRequest))
{
    TempData["formError"] = "Fill in the Captcha box.";
    return CurrentUmbracoPage();
}
0
votes

Ok I found a solution with detailed explanation in this Blog