From 8405c586f03a2a0a6271b5edd5ba9361f768da6a Mon Sep 17 00:00:00 2001
From: Ryan Cramer
Date: Thu, 3 Nov 2016 11:58:06 -0400
Subject: [PATCH] Add @iamwebrocker PR #18 which adds honeypot option to
comments form
---
.../FieldtypeComments/CommentForm.php | 38 ++++++++++++++++++-
.../Fieldtype/FieldtypeComments/comments.css | 4 ++
2 files changed, 41 insertions(+), 1 deletion(-)
diff --git a/wire/modules/Fieldtype/FieldtypeComments/CommentForm.php b/wire/modules/Fieldtype/FieldtypeComments/CommentForm.php
index 492b20be..ced12138 100644
--- a/wire/modules/Fieldtype/FieldtypeComments/CommentForm.php
+++ b/wire/modules/Fieldtype/FieldtypeComments/CommentForm.php
@@ -108,7 +108,11 @@ class CommentForm extends Wire implements CommentFormInterface {
// the name of a field that must be set (and have any non-blank value), typically set in Javascript to keep out spammers
// to use it, YOU must set this with a field from your own javascript, somewhere in the form
- 'requireSecurityField' => '',
+ 'requireSecurityField' => '',
+
+ // the name of a field that must NOT be set
+ // creates an input field that a (human) visitor should ignore, maybe hiding it with css is a good idea
+ 'requireHoneypotField' => '',
// should a redirect be performed immediately after a comment is successfully posted?
'redirectAfterPost' => null, // null=unset (must be set to true to enable)
@@ -254,7 +258,10 @@ class CommentForm extends Wire implements CommentFormInterface {
$attrs = $options['attrs'];
$id = $attrs['id'];
$submitKey = $id . "_submit";
+ $honeypot = $options['requireHoneypotField'];
$inputValues = array('cite' => '', 'email' => '', 'website' => '', 'stars' => '', 'text' => '', 'notify' => '');
+ if($honeypot) $inputValues[$honeypot] = '';
+
$user = $this->wire('user');
if($user->isLoggedin()) {
@@ -366,6 +373,18 @@ class CommentForm extends Wire implements CommentFormInterface {
"\n\t
";
}
+ // do we need to show the honeypot field?
+ $honeypot = $this->options['requireHoneypotField'];
+ if($honeypot) {
+ $honeypotLabel = isset($labels[$honeypot]) ? $labels[$honeypot] : '';
+ $honeypotValue = isset($inputValues[$honeypot]) ? $inputValues[$honeypot] : '';
+ $form .=
+ "\n\t