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

" . + "\n\t\t" . + "\n\t\t" . + "\n\t

"; + } + $form .= "\n\t

" . "\n\t\t" . @@ -427,6 +446,19 @@ 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

" . + "\n\t\t" . + "\n\t

"; + } + $form .= "\n\t

" . "\n\t\t