reCAPTCHA V2 with MVC in Umbraco v8 - Form submit without recaptcha validation
Hi Gurus,
I am so frustrated with this reCAPTCHA V2 using MVC in Umbraco v8.x.x. It does not check or validate recaptcha at all. It simply submit the form with no message. Please help.
I used recent latest video of creating Contact form and client dependency Umbraco v8 on youtube, When i submit the form it doesn't validate the Recaptha field.
using Project.Core.Services;
using Project.Core.ViewModels;
using Recaptcha.Web;
using Recaptcha.Web.Mvc;
using System.Web;
using System.Web.Mvc;
using Umbraco.Web;
using Umbraco.Web.Mvc;
namespace Project.Core.Controllers
{
public class ContactSurfaceController : SurfaceController
{
private readonly ISmtpService _smtpService;
public ContactSurfaceController(ISmtpService smtpService)
{
_smtpService = smtpService;
}
[HttpGet]
public ActionResult RenderForm()
{
ContactViewModel model = new ContactViewModel() { ContactFormId = CurrentPage.Id };
return PartialView("~/Views/Partials/Contact/contactForm.cshtml", model);
}
[HttpPost]
public ActionResult RenderForm(ContactViewModel model)
{
return PartialView("~/Views/Partials/Contact/contactForm.cshtml", model);
}
[HttpPost]
public ActionResult SubmitForm(ContactViewModel model)
{
if (!ModelState.IsValid)
{
return CurrentUmbracoPage();
}
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();
}
}
bool success = false;
if (ModelState.IsValid)
{
success = _smtpService.SendEmail(model);
}
var contactPage = UmbracoContext.Content.GetById(false, model.ContactFormId);
var successMessage = contactPage.Value<IHtmlString>("successMessage");
var errorMessage = contactPage.Value<IHtmlString>("errorMessage");
return PartialView("~/Views/Partials/Contact/result.cshtml", success ? successMessage : errorMessage);
}
}
}
and my View Model:
public class ContactViewModel
{
[Required(ErrorMessage = "Please enter your name")]
public string Name { get; set; }
[Required(ErrorMessage = "please enter your email address")]
[EmailAddress(ErrorMessage = "you must enter a valid email address")]
public string Email { get; set; }
[Required(ErrorMessage = "please enter your message")]
[MaxLength(length: 500, ErrorMessage = "Your message must be no longer than 500 characters")]
public string Message { get; set; }
@*[Required(ErrorMessage = "please confirm you are human")]
public string ErrorMessageCaptcha { get; set; }*@
public int ContactFormId { get; set; }
}
reCAPTCHA V2 with MVC in Umbraco v8 - Form submit without recaptcha validation
Hi Gurus,
I am so frustrated with this reCAPTCHA V2 using MVC in Umbraco v8.x.x. It does not check or validate recaptcha at all. It simply submit the form with no message. Please help.
I used recent latest video of creating Contact form and client dependency Umbraco v8 on youtube, When i submit the form it doesn't validate the Recaptha field.
and my View Model:
and my Partial View
is working on a reply...