This repository has been archived by the owner on Oct 12, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
SimpleContactFormConfig.php
278 lines (243 loc) · 10.2 KB
/
SimpleContactFormConfig.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
<?php namespace ProcessWire;
/**
* Class SimpleContactFormConfig
*/
class SimpleContactFormConfig extends ModuleConfig {
/**
* array Default config values
*/
public function getDefaults() {
$saveMessagesTemplate = $this->templates->get('simple_contact_form_messages');
return array(
'sendEmails' => true,
'emailTo' => '',
'emailSubject' => 'New Web Contact Form Submission',
'emailMessage' => '',
'emailServer' => '[email protected]',
'emailReplyTo' => '',
'allFields' => array(),
'redirectPage' => '',
'redirectSamePage' => true,
'saveMessages' => false,
'saveMessagesParent' => false,
'saveMessagesTemplate' => $saveMessagesTemplate ? $saveMessagesTemplate->id : null,
'saveMessagesScheme' => '',
'antiSpamTimeMin' => '1',
'antiSpamTimeMax' => '300',
'antiSpamPerDay' => '3',
'antiSpamExcludeIps' => '127.0.0.1',
'cleanup' => 0
);
}
/**
* Retrieves the list of config input fields
* Implementation of the ConfigurableModule interface
*
* @return InputfieldWrapper
*/
public function getInputfields() {
$allFields = isset($this->data['allFields']) ? $this->data['allFields'] : array();
if (!is_array($allFields)) $allFields = explode(',', $this->data['allFields']); // @todo: deprecated
// add prefix if necessary
// @todo: deprecated
foreach ($allFields as $key => $f) {
if (!$this->fields->get($f) || $f === 'email') $allFields[$key] = 'scf_' . $f;
}
// get inputfields
$inputfields = parent::getInputfields();
// fieldset general
$fieldset = $this->modules->get('InputfieldFieldset');
$fieldset->label = __('Email');
// field send emails
$field = $this->modules->get('InputfieldCheckbox');
$field->name = 'sendEmails';
$field->label = __('Send Emails?');
$field->description = __('Should Emails be sent?');
$field->value = 1;
$field->columnWidth = 50;
$fieldset->add($field);
// field email subject
$field = $this->modules->get('InputfieldText');
$field->name = 'emailSubject';
$field->label = __('Email: Subject');
$field->columnWidth = 50;
$field->required = 1;
$field->requiredIf = 'sendEmails=1';
$field->showIf = 'sendEmails=1';
$fieldset->add($field);
// field email to
$field = $this->modules->get('InputfieldText');
$field->name = 'emailTo';
$field->label = __('Email: "To"-Address');
$field->notes = __('Scheme: "Example <[email protected]>, Name <[email protected]>"');
$field->columnWidth = 33;
$field->required = 1;
$field->requiredIf = 'sendEmails=1';
$field->showIf = 'sendEmails=1';
$fieldset->add($field);
// field email server
$field = $this->modules->get('InputfieldText');
$field->name = 'emailServer';
$field->label = __('Email: "From"-Address');
$field->notes = __('Scheme: "FromName <[email protected]>"');
$field->columnWidth = 33;
$field->required = 1;
$field->requiredIf = 'sendEmails=1';
$field->showIf = 'sendEmails=1';
$fieldset->add($field);
// field email reply to
$field = $this->modules->get('InputfieldText');
$field->name = 'emailReplyTo';
$field->label = __('Email: "Reply-To"-Address');
$field->notes = __('Optional; Scheme: "ReplyToName <[email protected]>"');
$field->columnWidth = 34;
$field->requiredIf = 'sendEmails=1';
$field->showIf = 'sendEmails=1';
$fieldset->add($field);
$inputfields->add($fieldset);
// fieldset general
$fieldset = $this->modules->get('InputfieldFieldset');
$fieldset->label = __('Save Messages');
// save messages field
$field = $this->modules->get('InputfieldCheckbox');
$field->name = 'saveMessages';
$field->label = __('Save Messages');
$field->description = __('Should the messages be saved?');
$field->value = 1;
$field->columnWidth = 50;
$fieldset->add($field);
// save messages parent field
$field = $this->modules->get('InputfieldPageListSelect');
$field->name = 'saveMessagesParent';
$field->label = __('Select a parent for items');
$field->description = __('All items created and managed will live under the parent you select here.');
$field->notes = __('If no parent is selected, items will be placed as children of the root page (not recommended).');
$field->required = 1;
$field->requiredIf = 'saveMessages=1';
$field->showIf = 'saveMessages=1';
$field->columnWidth = 50;
$fieldset->add($field);
// save messages template field
$field = $this->modules->get('InputfieldSelect');
$field->name = 'saveMessagesTemplate';
$field->label = __('Save messages template');
$field->description = __('Choose the template, that is used to save messages.');
foreach ($this->templates->getAll() as $key => $template) {
if ($template->flags && Template::flagSystem) continue;
$field->addOption($key, $template);
}
$field->required = 1;
$field->requiredIf = 'saveMessages=1';
$field->showIf = 'saveMessages=1';
$field->columnWidth = 50;
$fieldset->add($field);
// save messages name scheme
$field = $this->modules->get('InputfieldAsmSelect');
$field->description = __('Add all fields which should be used as part of the page name. Choose from existing ones, you may have to add them first below and save.');
$field->notes = __('The page name starts with a timestamp. All fields added above will be appended.');
$field->addOption('', '');
$field->label = __('Select page name fields');
$field->attr('name', 'saveMessagesScheme');
$field->showIf = 'saveMessages=1';
$field->columnWidth = 50;
foreach ($allFields as $aField) {
if ($f = $this->fields->get($aField)) {
$field->addOption($f->name, $f->name);
}
}
// $field->attr('value', $allFields);
$fieldset->add($field);
$inputfields->add($fieldset);
// fieldset fields
$fieldset = $this->modules->get('InputfieldFieldset');
$fieldset->label = __('Fields');
// allFields field
$field = $this->modules->get('InputfieldAsmSelect');
$field->description = __('Add all fields (choose from existing ones) which should be attached to the form.');
$field->addOption('', '');
$field->label = __('Select form fields');
$field->attr('name', 'allFields');
$field->required = true;
$field->columnWidth = 50;
foreach ($this->fields as $f) {
// skip system fields
if ($f->flags & Field::flagSystem || $f->flags & Field::flagPermanent) continue;
$field->addOption($f->name, $f->name);
}
$field->attr('value', $allFields);
$fieldset->add($field);
// field addFields
$field = $this->modules->get('InputfieldText');
$field->name = 'addFields';
$field->label = __('Create and add fields');
$field->description = __('If you want to add non-existing fields, add them here as a comma-separated list.');
$field->columnWidth = 50;
$fieldset->add($field);
$inputfields->add($fieldset);
// redirect to the same page to get rid of POST vars
$field = $this->modules->get('InputfieldCheckbox');
$field->name = 'redirectSamePage';
$field->label = __('Redirect to the same page after successfull submission');
$field->description = __('OPTIONAL: If you prefer to stay on the same page without adding url parameter, just leave this field empty. Redirecting to the same page prevents form resubmission.');
$field->value = 1;
$field->columnWidth = 50;
$fieldset->add($field);
// redirect to a specific URL after successfull submission
$field = $this->modules->get('InputfieldPageListSelect');
$field->name = 'redirectPage';
$field->label = __('Redirect to a specific page after successfull submission ');
$field->description = __('OPTIONAL: If you prefer to stay on the same page, just leave this field empty.');
$field->columnWidth = 50;
$fieldset->add($field);
// fieldset messages
$fieldset = $this->modules->get('InputfieldFieldset');
$fieldset->label = __('Messages');
$fieldset->showIf = 'sendEmails=1';
$fieldset->collapsed = Inputfield::collapsedYes;
// field email message
$field = $this->modules->get('InputfieldTextarea');
$field->name = 'emailMessage';
$field->label = __('Email Message');
$field->description = __('Email message (optional - overwrites basic mail template).');
$field->notes = __('Use %fieldName% as placeholder, for example %fullName%.');
$field->rows = 5;
$fieldset->add($field);
$inputfields->add($fieldset);
// fieldset spam
$fieldset = $this->modules->get('InputfieldFieldset');
$fieldset->label = __('Spam');
$fieldset->collapsed = Inputfield::collapsedYes;
// antiSpamTimeMin
$field = $this->modules->get('InputfieldInteger');
$field->name = 'antiSpamTimeMin';
$field->label = __('Minimum Time');
$field->description = __('It parses the time the user needs to fill out the form. If the time is below a minimum time, the submission is treated as Spam.');
$field->notes = __('- in seconds -');
$field->columnWidth = 50;
$fieldset->add($field);
// antiSpamTimeMax
$field = $this->modules->get('InputfieldInteger');
$field->name = 'antiSpamTimeMax';
$field->label = __('Maximum Time');
$field->description = __('It parses the time the user needs to fill out the form. If the time is over a maximum time, the submission is treated as Spam.');
$field->notes = __('- in seconds -');
$field->columnWidth = 50;
$fieldset->add($field);
// antiSpamPerDay
$field = $this->modules->get('InputfieldInteger');
$field->name = 'antiSpamPerDay';
$field->label = __('Restrict Submissions');
$field->description = __('How often the form is allowed to be submitted by a single IP address in the last 24 hours.');
$field->columnWidth = 50;
$fieldset->add($field);
// antiSpamPerDay
$field = $this->modules->get('InputfieldText');
$field->name = 'antiSpamExcludeIps';
$field->label = __('Exclude IPs');
$field->description = __('Comma-Seperated list of IP addresses to be excluded from IP filtering.');
$field->columnWidth = 50;
$fieldset->add($field);
$inputfields->add($fieldset);
return $inputfields;
}
}