Copied to clipboard

Flag this post as spam?

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


  • Wihlborg Inge 21 posts 161 karma points
    Feb 11, 2017 @ 18:30
    Wihlborg Inge
    0

    Adding reCaptcha in the Contact section

    Hi again, I have one more question about the contact section form in Umazel Starter Kit Theme.

    I have tried to add a reCaptcha to the view but I don't know how to catch the reCaptcha error messages and present them in the view probably by using javascript.

    This is the controller

    [HttpPost]
        [NotChildAction]
        public ActionResult Submit(ContactViewModel form)
        {
            RecaptchaVerificationHelper recaptchaHelper = this.GetRecaptchaVerificationHelper();
            if (string.IsNullOrEmpty(recaptchaHelper.Response))
            {
                ModelState.AddModelError("reCAPTCHA", "Please complete the reCAPTCHA");
                return CurrentUmbracoPage();
            }
            else
            {
                RecaptchaVerificationResult recaptchaResult = recaptchaHelper.VerifyRecaptchaResponse();
                if (recaptchaResult != RecaptchaVerificationResult.Success)
                {
                    ModelState.AddModelError("reCAPTCHA", "The reCAPTCHA is incorrect");
                    return CurrentUmbracoPage();
                }
            }
    
            if (!ModelState.IsValid)
            {
                return Json(new { Success = false });
            }
    

    And a think I have to add the messages in the script part of the view

    <script type="text/javascript">
    
    function ShowContactError() {
         $(".errorContent").show();
            $("#contactFormHolder").hide();
    }
    
    function ShowContactSuccess(arg) {
        if (arg.Success === true) {
            $("#contactSuccess").show();
            $("#contactFormHolder").hide();
        }
        else
        {
            $(".successContent").show();
            $("#contactFormHolder").hide();
    
        }
    }
    

    BR Inge Wihlborg

  • Nitin Anand 46 posts 178 karma points
    Jan 06, 2019 @ 06:19
    Nitin Anand
    0

    Did you download recaptcha element by nuget or how did you added to project?

  • Wihlborg Inge 21 posts 161 karma points
    Jan 07, 2019 @ 14:56
    Wihlborg Inge
    0

    Yes I did download the recaptcha from nuget.

Please Sign in or register to post replies

Write your reply to:

Draft