Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/themefisher/airspace-hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSomrat <58769763+tfsomrat@users.noreply.github.com>2021-10-31 07:12:41 +0300
committerGitHub <noreply@github.com>2021-10-31 07:12:41 +0300
commit98d5ea95d71f04243572655395452ffe35b1aaec (patch)
treee07341c30b6181d2b1d1a9e95a186b5ce1a855b6
parent2497375595723a0bdbbe618c8597854238d1ce6e (diff)
parentd7653964080f02882a5f981208522bb283e71913 (diff)
Merge pull request #208 from fredleger/feat/add-recaptcha
feature: add recaptcha v3 to contact form
-rw-r--r--exampleSite/config/_default/params.toml6
-rw-r--r--layouts/_default/contact.html5
-rw-r--r--layouts/partials/head.html15
3 files changed, 24 insertions, 2 deletions
diff --git a/exampleSite/config/_default/params.toml b/exampleSite/config/_default/params.toml
index fabd885..73d5234 100644
--- a/exampleSite/config/_default/params.toml
+++ b/exampleSite/config/_default/params.toml
@@ -31,11 +31,15 @@ copyright = "Designed By [Themefisher](https://themefisher.com/) & Developed By
custom_script= ""
# google tag manager, see https://developers.google.com/tag-manager/
google_tag_manager = "" # example: G-XXXXXXXXXX
+# recaptch v3 site key
+recaptcha_site_key = "xxx-xxxxxxxxxxxxxxxxxxxxxxxx"
[contact.form]
enable = true
# Whether to use [Netlify Forms](https://docs.netlify.com/forms/setup/)
use_netlify = true
+# Whether to use recaptch v3 in form
+use_recaptcha = true
# Form action
## Fill in your Form ID URL for Formspree.io, e.g. `https://formspree.io/f/{form_id}`
## Ignored if `use_netlify = true` (custom [success page](https://docs.netlify.com/forms/setup/#success-messages) is already included)
@@ -127,4 +131,4 @@ link = "#"
[[social]]
title = "linkedin"
icon = "fab fa-linkedin" # fontawesome icon pack : https://fontawesome.com/icons/
-link = "#" \ No newline at end of file
+link = "#"
diff --git a/layouts/_default/contact.html b/layouts/_default/contact.html
index 1d6579c..e48151e 100644
--- a/layouts/_default/contact.html
+++ b/layouts/_default/contact.html
@@ -26,6 +26,11 @@
<input name="nhp" type="text" class="form-control" placeholder="Are you made of flesh and bone?">
</div>
{{- end }}
+ {{ if .use_recaptcha -}}
+ <div class="form-group-h">
+ <input type="hidden" id="captchaResponse" name="g-recaptcha-response">
+ </div>
+ {{- end }}
</div>
</div>
<div class="col-md-6 col-sm-12">
diff --git a/layouts/partials/head.html b/layouts/partials/head.html
index 15fd704..7ea6eef 100644
--- a/layouts/partials/head.html
+++ b/layouts/partials/head.html
@@ -172,4 +172,17 @@
</script>
{{ end }}
{{ end }}
-{{ end }} \ No newline at end of file
+{{ end }}
+
+<!-- Google reCaptcha -->
+{{ if site.Params.contact.form.use_recaptcha }}
+<script src="https://www.google.com/recaptcha/api.js?render={{ site.Params.recaptcha_site_key }}"></script>
+<script>
+ grecaptcha.ready(function() {
+ grecaptcha.execute('{{ site.Params.recaptcha_site_key }}', {action: 'homepage'})
+ .then(function(token) {
+ document.getElementById('captchaResponse').value = token;
+ });
+ });
+</script>
+{{ end }}