From d34dc542b89737deff26647bc66c4be338e6964d Mon Sep 17 00:00:00 2001 From: eriktacknoaignite Date: Wed, 2 Apr 2025 18:56:03 +0200 Subject: [PATCH] add clientscript url property to HcaptchaElementBlock On the pro plan, you should use alternative script URLs to improve the experience in certain scenarios - like for visitors from mainland China. This would allow the usage of an alternative captcha client script, but otherwise fallback to the default. Note: It could also be made language branch dependent using [CultureSpecific] for the property above line 177 --- .../Elements/HcaptchaElementBlock.cs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/EPiServer.Forms.Samples/Implementation/Elements/HcaptchaElementBlock.cs b/src/EPiServer.Forms.Samples/Implementation/Elements/HcaptchaElementBlock.cs index 3ee6c10..d2083f7 100644 --- a/src/EPiServer.Forms.Samples/Implementation/Elements/HcaptchaElementBlock.cs +++ b/src/EPiServer.Forms.Samples/Implementation/Elements/HcaptchaElementBlock.cs @@ -169,13 +169,28 @@ public override string EditViewFriendlyTitle } } + /// + /// Custom script URL for use in certain scenarios, like mainland China. See more here: https://docs.hcaptcha.com/faq/#does-hcaptcha-support-access-by-users-in-china. + /// Will use the default URL if not set. + /// + [Display(GroupName = SystemTabNames.Settings, Order = -3300)] + public virtual string ClientScriptUrl { get; set; } + + private const string DEFAULT_CLIENT_SCRIPT_URL = "https://js.hcaptcha.com/1/api.js"; + public IEnumerable> GetExtraResources() { return new List>() { new Tuple( - "script", string.Format("https://js.hcaptcha.com/1/api.js") + "script", !string.IsNullOrEmpty(ClientScriptUrl) ? ClientScriptUrl : DEFAULT_CLIENT_SCRIPT_URL ) }; } + + public override void SetDefaultValues(ContentType contentType) + { + base.SetDefaultValues(contentType); + ClientScriptUrl = DEFAULT_CLIENT_SCRIPT_URL; + } } -} \ No newline at end of file +}