CaptchaBuilder renders the captcha image, input and refresh action while keeping the existing GDF session-backed validation endpoint.

Presentation Styles

Normal captcha

Captcha
Captcha is required.
C#
@(Html.CaptchaBuilder()
    .SetInput("captchaNormal", "captchaNormal")
    .SetLabel("Captcha")
    .SetLabelIcon(IconStruct.Bootstrap("bi-shield-check"))
    .SetPlaceholder("Captcha")
    .Render())

Floating captcha

Captcha
Captcha is required.
C#
@(Html.CaptchaBuilder()
    .SetInput("captchaFloating", "captchaFloating")
    .SetLabel("Captcha")
    .SetLabelPresentation(FormLabelPresentation.Floating)
    .SetLabelIcon(IconStruct.Bootstrap("bi-shield-check"))
    .SetPlaceholder("Captcha")
    .Render())

Inline captcha

Captcha
Captcha is required.
C#
@(Html.CaptchaBuilder()
    .SetInput("captchaInline", "captchaInline")
    .SetLabel("Captcha")
    .SetLabelPresentation(FormLabelPresentation.Inline)
    .SetLabelIcon(IconStruct.Bootstrap("bi-shield-check"))
    .SetPlaceholder("Captcha")
    .Render())

Grouped captcha

Captcha
Captcha is required.
C#
@(Html.CaptchaBuilder()
    .SetInput("captchaGrouped", "captchaGrouped")
    .SetLabel("Captcha")
    .SetLabelPresentation(FormLabelPresentation.Group)
    .SetLabelIcon(IconStruct.Bootstrap("bi-shield-check"))
    .SetPlaceholder("Captcha")
    .Render())

Interactive Captcha

Captcha
Captcha is required.
Required field

Code Examples

Captcha.cshtml
@Html.CaptchaBuilder()
    .SetInput("captchaValue", "captchaValue")
    .SetLabel("Captcha")
    .SetLabelIcon(IconStruct.Bootstrap("bi-shield-check"))
    .SetPlaceholder("Captcha")
    .Render()

@Html.CaptchaBuilder()
    .SetInput("captchaValue", "captchaValue")
    .SetLabelPresentation(FormLabelPresentation.Floating)
    .SetImageHeight(40)
    .SetRefreshVariant(VariantStyle.Success)
    .Render()

@Html.CaptchaBuilder()
    .SetInput("captchaValue", "captchaValue")
    .SetLabelPresentation(FormLabelPresentation.Inline)
    .Render()

@Html.CaptchaBuilder()
    .SetInput("captchaValue", "captchaValue")
    .SetLabelPresentation(FormLabelPresentation.Group)
    .SetLabelIcon(IconStruct.Bootstrap("bi-shield-check"))
    .Render()

[HttpPost]
[ValidateAntiForgeryToken]
public IActionResult Captcha(string captchaValue)
{
    if (CaptchaFactory.TestCaptcha(HttpContext, captchaValue))
    {
        Page.AddSuccess(WebLocalizer.GetInternal("FormBuilder_Captcha_Valid_Title"), WebLocalizer.GetInternal("FormBuilder_Captcha_Valid_Message"));
    }
    else
    {
        Page.AddWarning(WebLocalizer.GetInternal("FormBuilder_Captcha_Invalid_Title"), WebLocalizer.GetInternal("FormBuilder_Captcha_Invalid_Message"));
    }

    return View();
}