Skip to content

Commit d477a17

Browse files
avicnduguCopilot
andauthored
Stopping basic spam bots from filling contact form (#80)
* Prevent form submit if username form field is filled * Clean up white space in the diff * Clean up white space in the diff(2) * Clean up white space in the diff(3) * Remove placeholder text to avoid confusion if hidden field exposed unintentionally Co-authored-by: Copilot <[email protected]> * Cleanup whitespace * Remove placeholder text to avoid confusion if hidden field exposed --------- Co-authored-by: Copilot <[email protected]>
1 parent 89df3a6 commit d477a17

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

_includes/contact.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ <h3 class="section-subheading text-muted">{{ site.data.sitetext[site.locale].con
2323
required="required" data-validation-required-message="{{ site.data.sitetext[site.locale].contact.name-validation | default: "Please enter your name." }}">
2424
<p class="help-block text-danger"></p>
2525
</div>
26+
<div class="form-group d-none">
27+
<input name="username" class="form-control" id="username" type="text" tabindex="-1" autocomplete="off">
28+
</div>
2629
<div class="form-group">
2730
<input name="_replyto" class="form-control" id="email" type="email"
2831
placeholder="{{ site.data.sitetext[site.locale].contact.email | default: "Email*" }}"
@@ -84,6 +87,9 @@ <h3 class="section-subheading text-muted">{{ site.data.sitetext.contact.text | d
8487
required="required" data-validation-required-message="{{ site.data.sitetext.contact.name-validation | default: "Please enter your name." }}">
8588
<p class="help-block text-danger"></p>
8689
</div>
90+
<div class="form-group d-none">
91+
<input name="username" class="form-control" id="username" type="text" tabindex="-1" autocomplete="off">
92+
</div>
8793
<div class="form-group">
8894
<input name="_replyto" class="form-control" id="email" type="email"
8995
placeholder="{{ site.data.sitetext.contact.email | default: "Email*" }}"
@@ -122,4 +128,4 @@ <h3 class="section-subheading text-muted">{{ site.data.sitetext.contact.text | d
122128
</div>
123129
</section>
124130
{% endif %}
125-
<!-- End Contact -->
131+
<!-- End Contact -->

assets/js/contact_me.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ $(function() {
1212
// get values from FORM
1313
var url = "https://formspree.io/" + "{% if site.formspree_form_path %}{{ site.formspree_form_path }}{% else %}{{ site.email }}{% endif %}";
1414
var name = $("input#name").val();
15+
var username = $("input#username").val();
1516
var email = $("input#email").val();
1617
var phone = $("input#phone").val();
1718
var message = $("textarea#message").val();
@@ -22,6 +23,7 @@ $(function() {
2223
}
2324
$this = $("#sendMessageButton");
2425
$this.prop("disabled", true); // Disable submit button until AJAX call is complete to prevent duplicate messages
26+
if(username === ''){ // Disable's form submit if hidden input(username) has been filled
2527
$.ajax({
2628
url: url,
2729
type: "POST",
@@ -64,6 +66,7 @@ $(function() {
6466
}, 1000);
6567
}
6668
});
69+
}
6770
},
6871
filter: function() {
6972
return $(this).is(":visible");

0 commit comments

Comments
 (0)