Adds the Google Invisible Recaptcha form component to your MVC Site.
CitroDigital.InvisibleRecaptcha
Nuget Package to your MVC SiteTo remove the label from the form widget see Adding contextual markup to forms of the form widget.
public class FormFieldMarkupInjection
{
public static void RegisterEventHandlers()
{
FormFieldRenderingConfiguration.GetConfiguration.Execute += InjectMarkupIntoKenticoComponents;
}
private static void InjectMarkupIntoKenticoComponents(object sender, GetFormFieldRenderingConfigurationEventArgs e)
{
//Hides the recaptcha form label on the field using display:none;
e.HideInvisibleRecaptchaLabel();
//To do it yourself using a class
if (e.FormComponent.Definition.Identifier == InvisibleRecaptchaComponent.IDENTIFIER)
{
if (e.Configuration.LabelHtmlAttributes.ContainsKey("class"))
{
e.Configuration.LabelHtmlAttributes["class"] += " hide";
}
else
{
e.Configuration.LabelHtmlAttributes["class"] = "hide";
}
}
}
}
@Html.RenderRecaptchaLib()
There is an HtmlHelper extensions @Html.InvisibleRecaptchaFor(Expression<Func<TModel, TProperty>> expression, string action = null)
that you can utilize to render the invisible recaptcha inside of a razor form.
There is also a ValidationAttribute called InvisibleRecaptcha that will validate recaptcha property value, with the specified action
InvisibleRecaptcha Attribute has two properties Action and Score.
public class NewsletterSubscribeViewModel
{
[DataType(DataType.EmailAddress)]
[Required(ErrorMessage = "The Email address cannot be empty.")]
[DisplayName("Email address")]
[EmailAddress(ErrorMessage = "Invalid email address.")]
[MaxLength(254, ErrorMessage = "The Email address cannot be longer than 254 characters.")]
public string Email
{
get;
set;
}
/// <summary>
/// Indicates whether the newsletter requires double-opt in for subscription.
/// Allows the view to display appropriate information to newly subscribed users.
/// </summary>
[Bindable(false)]
public bool RequireDoubleOptIn
{
get;
set;
}
[InvisibleRecaptcha(Action = "NewsletterSubscription")]
public string Recaptcha { get; set; }
}
@model NewsletterSubscribeViewModel
@Html.Kentico().AntiForgeryToken()
<div class="input-group margin-top-1">
@Html.TextBoxFor(_ => _.Email, new { @class = "input-group-field", placeholder = "Email Address" })
<div class="input-group-button">
<input type="submit" class="button secondary" value="Submit" />
</div>
</div>
<div class="input-group margin-top-1">
@Html.ValidationMessageFor(_ => _.Email, "Please fill out your Email Address", htmlAttributes: new Dictionary<string, object>() { { "class", "form-error" } })
</div>
@Html.InvisibleRecaptchaFor(_ => _.Recaptcha, "NewsletterSubscription")
@Html.ValidationMessageFor(_ => _.Recaptcha)
You can submit bugs through the issue list and we will get to them as soon as we can.