1
1
# SpamProtection Module
2
2
3
+ [ ![ Build Status] ( https://secure.travis-ci.org/silverstripe/silverstripe-spamprotection.png?branch=master )] ( http://travis-ci.org/silverstripe/silverstripe-spamprotection )
4
+ ![ helpfulrobot] ( https://helpfulrobot.io/silverstripe/spamprotection/badge )
5
+
6
+
3
7
## Maintainer Contact
4
8
5
9
* Saophalkun Ponlu
@@ -14,12 +18,110 @@ SilverStripe 3.0.0 or greater
14
18
15
19
## Documentation
16
20
17
- See docs/
21
+ This module provides a generic, consistent API for adding spam protection to
22
+ your SilverStripe Forms. This does not provide any spam protection out of the
23
+ box, for that, you must also download one of the spam protection
24
+ implementations. Currently available options are:
25
+
26
+ * [ Mollom] ( https://github.com/silverstripe/silverstripe-mollom )
27
+ * [ Recaptcha] ( https://github.com/chillu/silverstripe-recaptcha )
28
+ * [ MathSpamProtection] ( https://github.com/silverstripe/silverstripe-mathspamprotection )
29
+ * [ Akismet] ( https://github.com/tractorcow/silverstripe-akismet )
30
+
31
+ As a developer you can also provide your own protector by creating a class which
32
+ implements the ` SpamProtector ` interface. More on that below.
33
+
34
+ ## Configuring
35
+
36
+ After installing this module and a protector of your choice (i.e mollom) you'll
37
+ need to rebuild your database through ` dev/build ` and set the default protector
38
+ via SilverStripe's config system. This will update any Form instances that have
39
+ spam protection hooks with that protector.
40
+
41
+ * mysite/_ config/spamprotection.yml*
42
+
43
+ ---
44
+ name: spamprotection
45
+ ---
46
+ FormSpamProtectionExtension:
47
+ default_spam_protector: MollomSpamProtector
48
+
49
+ To add spam protection to your form instance call ` enableSpamProtection ` .
50
+
51
+ // your existing form code
52
+ $form = new Form( .. );
53
+ $form->enableSpamProtection();
54
+
55
+ The logic to perform the actual spam validation is controlled by each of the
56
+ individual ` SpamProtector ` implementation since they each require a different
57
+ implementation client side or server side.
58
+
59
+ ### Options
60
+
61
+ ` enableSpamProtection ` takes a hash of optional configuration values.
62
+
63
+ $form->enableSpamProtection(array(
64
+ 'protector' => 'MathSpamProtector',
65
+ 'name' => 'Captcha'
66
+ ));
67
+
68
+ Options to configure are:
69
+
70
+ * ` protector ` * a class name string or class instance which implements
71
+ ` SpamProtector ` . Defaults to your
72
+ ` FormSpamProtectionExtension.default_spam_protector ` value.
73
+
74
+ * ` name ` * the form field name argument for the Captcha. Defaults to ` Catcha ` .
75
+ * ` title ` * title of the Captcha form field. Defaults to ` '' `
76
+ * ` insertBefore ` * name of existing field to insert the spam protection field prior to
77
+ * ` mapping ` * an array mapping of the Form fields to the standardized list of
78
+ field names. The list of standardized fields to pass to the spam protector are:
79
+
80
+ title
81
+ body
82
+ contextUrl
83
+ contextTitle
84
+ authorName
85
+ authorMail
86
+ authorUrl
87
+ authorIp
88
+ authorId
89
+
90
+ ## Defining your own ` SpamProtector `
91
+
92
+ Any class that implements ` SpamProtector ` and the ` getFormField() ` method can
93
+ be set as the spam protector. The ` getFormField() ` method returns the
94
+ ` FormField ` to be inserted into the ` Form ` . The ` FormField ` returned should be
95
+ in charge of the validation process.
96
+
97
+ <?php
98
+
99
+ class CustomSpamProtector implements SpamProtector {
100
+
101
+ public function getFormField($name = null, $title = null, $value = null) {
102
+ // CaptchaField is a imagined class which has some functionality.
103
+ // See silverstripe-mollom module for an example.
104
+ return new CaptchaField($name, $title, $value);
105
+ }
106
+ }
107
+
108
+
109
+ ## Using Spam Protection with User Forms
110
+
111
+ This module provides an EditableSpamProtectionField wrapper which you can add
112
+ to your UserForm instances. After installing this module and running /dev/build
113
+ to rebuild the database, your Form Builder interface will have an option for
114
+ ` Spam Protection Field ` . The type of spam protection used will be based on your
115
+ currently selected SpamProtector instance.
18
116
19
- ## Installation Instructions
117
+ ## Releasing code with Spam Protection support
20
118
21
- See docs/Install
119
+ Spam protection is useful to provide but in some cases we do not want to require
120
+ the developer to use spam protection. In that case, modules can provide the
121
+ following pattern
22
122
23
- ## Usage Overview
123
+ $form = new Form(..);
24
124
25
- See docs/Install
125
+ if($form->hasExtension('FormSpamProtectionExtension')) {
126
+ $form->enableSpamProtection();
127
+ }
0 commit comments