make the recaptcha a required field RRS feed

  • Question

  • User-540818677 posted

    I am working on an asp.net core mvc web application, and i have added the following field to show google recaptcha version 2:-

    <div class="form-group">
          <div class="col-md-2"></div>
                <div class="col-md-10">
                    <div class="g-recaptcha" data-callback="recaptchaCallback" data-sitekey="@ViewData["ReCaptchaKey"]">
    //code goes here
    @section Scripts {
    <script src='https://www.google.com/recaptcha/api.js'></script>}

    and inside my action method i am checking if the user select the recaptcha or not, as follow:-

    public async Task<IActionResult> SearchNPI(ContactinfoCreate ci)
                //add uncompleted entry
                ViewData["ReCaptchaKey"] = _configuration.GetSection("GoogleReCaptcha:key").Value;
                if (!ReCaptchaPassed(
                Request.Form["g-recaptcha-response"], // that's how you get it from the Request object
                    ModelState.AddModelError(string.Empty, "Please enter CAPTCHA");

    but on the client side how i can ake the recaptcha required filed, so the user can not submit the form unless he/she select the recaptcha?

    Saturday, July 11, 2020 1:10 PM

All replies