Stackoverflow 社区您好,
有人可以分享他们对如何在 Umbraco 前端提交表单期间调用 javascript 函数然后继续其余工作流程的见解吗?
由于我正在实现一个不可见的验证码,我们必须触发
grecaptcha.execute();
来生成客户端令牌。
我必须在提交表单时执行此脚本,以便生成验证码令牌。
<script type="text/javascript">
function onSubmit(event){
event.preventDefault();
grecaptcha.execute();
}
</script>
然后在
ValidateField
方法中使用
var reCaptchaResponse = context.Request.Form["g-recaptcha-response"].ToString();
我可以获取客户端令牌进行验证。
任何线索表示赞赏!
到目前为止,我已经尝试检查 SurafceController 的文档,但是,我想要执行的是前端而不是后端。
对我有用的是在自定义字段类型中添加
Html.AddFormThemeScriptFile("https://www.google.com/recaptcha/api.js");
触发了javascript函数并在div中添加了数据回调属性。
<div class="g-recaptcha"
data-sitekey="@siteKey"
data-callback="onSubmit"
data-size="invisible">
</div>
```