Add spam honeypot to contact form on homepage

This commit is contained in:
Garrett Mills 2022-07-10 00:28:42 -05:00
parent 48edd7134f
commit a3901b7d1e
2 changed files with 11 additions and 0 deletions

View File

@ -112,6 +112,12 @@ export class Home extends Controller {
} }
async contact(data: Valid<ContactForm>) { async contact(data: Valid<ContactForm>) {
// If the request has an "e-mail" field, then this was likely filled out by a spam
// bot, as this field is hidden on the form. So, reject it.
if ( this.request.input('e-mail') ) {
data.name = `SPAM: ${data.name}` // for testing, just alter the name
}
const submission = make<ContactSubmission>(ContactSubmission) const submission = make<ContactSubmission>(ContactSubmission)
submission.name = data.name submission.name = data.name
submission.email = data.email submission.email = data.email

View File

@ -43,6 +43,7 @@ block content
form#contact-form(method='post' action=named('contact')) form#contact-form(method='post' action=named('contact'))
.form-group .form-group
input#contactEmail.form-control(type='email' name='email' placeholder='E-Mail Address' required) input#contactEmail.form-control(type='email' name='email' placeholder='E-Mail Address' required)
input#contactEEmail(type='email' name='e-mail')
.form-group .form-group
input#contactFirst.form-control(name='name' placeholder='Name' required) input#contactFirst.form-control(name='name' placeholder='Name' required)
.form-group .form-group
@ -65,3 +66,7 @@ block content
.row.mt-4 .row.mt-4
.col-12.text-center .col-12.text-center
a.button(href="/feed") view all a.button(href="/feed") view all
block append script
script.
document.getElementById('contactEEmail').style.display = 'none'