diff --git a/_config.yml b/_config.yml index 91fe1d0..0b88343 100644 --- a/_config.yml +++ b/_config.yml @@ -327,6 +327,9 @@ t: label: "Objet" message: label: "Votre message" + captcha: + label: "Question anti-spam : combien font 3 + 3 ?" + error: "Merci de répondre correctement à la question anti-spam." confirmation: title: "Message envoyé !" subtitle: "Merci de nous avoir contacté, nous revenons vers vous le plus vite possible !" @@ -504,6 +507,9 @@ t: privacyPhrase: "We will never share your email without your consent." message: label: "Your message" + captcha: + label: "Anti-spam question: what is 3 + 3?" + error: "Please answer the anti-spam question correctly." confirmation: title: "Message sent!" subtitle: "Thank you for contacting us, we will get back to you as soon as possible!" @@ -680,6 +686,9 @@ t: privacyPhrase: "Mai compartirem el teu correu electrònic sense el teu consentiment." message: label: "El teu missatge" + captcha: + label: "Pregunta anti-brossa: quant fan 3 + 3?" + error: "Respon correctament a la pregunta anti-brossa." confirmation: title: "Missatge enviat!" subtitle: "Gràcies per contactar amb nosaltres, us respondrem el més aviat possible!" @@ -855,7 +864,10 @@ t: label: "Su dirección de correo electrónico" privacyPhrase: "Nunca compartiremos su correo electrónico sin su consentimiento." message: - label: "Tu mensa" + label: "Tu mensaje" + captcha: + label: "Pregunta anti-spam: ¿cuánto es 3 + 3?" + error: "Responda correctamente a la pregunta anti-spam." confirmation: title: "¡Mensaje enviado!" subtitle: "¡Gracias por contactarnos, nos pondremos en contacto con usted lo antes posible!" diff --git a/_includes/contact-form.html b/_includes/contact-form.html index d24d416..0e6c380 100644 --- a/_includes/contact-form.html +++ b/_includes/contact-form.html @@ -12,7 +12,18 @@

{{ site.t.[layout.lang].contactForm.title }}

class="gform" method="POST" action="https://script.google.com/macros/s/AKfycbxzvB_Jbta7xCVuz-iThqXftPb1DcBTf-P-ah4KnbxBn3OhcHJF/exec" + data-captcha-error="{{ site.t.[layout.lang].contactForm.captcha.error }}" > +
{{ site.t.[layout.lang].contactForm.title }} name="message" >
+
+ + +
diff --git a/js/form-submission-handler.js b/js/form-submission-handler.js index ab620de..4b90d9b 100644 --- a/js/form-submission-handler.js +++ b/js/form-submission-handler.js @@ -3,12 +3,17 @@ function getFormData(form) { var elements = form.elements; var honeypot; + var captcha; var fields = Object.keys(elements).filter(function(k) { if (elements[k].name === "honeypot") { honeypot = elements[k].value; return false; } + if (elements[k].name === "captcha") { + captcha = elements[k].value; + return false; + } return true; }).map(function(k) { if(elements[k].name !== undefined) { @@ -47,7 +52,7 @@ formData.formGoogleSendEmail = form.dataset.email || ""; // no email by default - return {data: formData, honeypot: honeypot}; + return {data: formData, honeypot: honeypot, captcha: captcha}; } function handleFormSubmit(event) { // handles form submit without any jquery @@ -60,6 +65,11 @@ if (formData.honeypot) { return false; } + + if ((formData.captcha || "").trim() !== "6") { + alert(form.dataset.captchaError || "Please answer the anti-spam question."); + return false; + } disableAllButtons(form); var url = form.action; @@ -102,4 +112,4 @@ buttons[i].disabled = true; } } - })(); \ No newline at end of file + })();