1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
*
|
6
|
* Menu callbacks and functions for configuring and editing webforms.
|
7
|
*/
|
8
|
|
9
|
/**
|
10
|
* Main configuration form for editing a webform node.
|
11
|
*/
|
12
|
function webform_configure_form($form, &$form_state, $node) {
|
13
|
form_load_include($form_state, 'inc', 'webform', 'includes/webform.components');
|
14
|
|
15
|
$form['#attached']['library'][] = array('webform', 'admin');
|
16
|
|
17
|
// Refresh the entity cache to get the lastest submission number.
|
18
|
$nid = $node->nid;
|
19
|
entity_get_controller('node')->resetCache(array($nid));
|
20
|
$node = node_load($nid);
|
21
|
|
22
|
$form['#node'] = $node;
|
23
|
|
24
|
$form['#submit'] = array(
|
25
|
'webform_configure_form_submit',
|
26
|
'webform_configure_form_submit_save',
|
27
|
);
|
28
|
|
29
|
$form['nid'] = array(
|
30
|
'#type' => 'value',
|
31
|
'#value' => $node->nid,
|
32
|
);
|
33
|
|
34
|
/* Start Edit Form */
|
35
|
$form['submission'] = array(
|
36
|
'#type' => 'fieldset',
|
37
|
'#title' => t('Submission settings'),
|
38
|
'#collapsible' => TRUE,
|
39
|
'#collapsed' => FALSE,
|
40
|
'#weight' => -4,
|
41
|
);
|
42
|
|
43
|
$form['submission']['confirmation'] = array(
|
44
|
'#type' => 'text_format',
|
45
|
'#title' => t('Confirmation message'),
|
46
|
'#description' => t('Message to be shown upon successful submission. If the redirection location is set to <em>Confirmation page</em> it will be shown on its own page, otherwise this displays as a message. Supports Webform token replacements.') . ' ' . theme('webform_token_help', array('groups' => array('node', 'submission'))),
|
47
|
'#default_value' => $node->webform['confirmation'],
|
48
|
'#cols' => 40,
|
49
|
'#rows' => 10,
|
50
|
'#format' => $node->webform['confirmation_format'],
|
51
|
'#parents' => array('confirmation'),
|
52
|
);
|
53
|
|
54
|
// Redirection settings.
|
55
|
if (strpos($node->webform['redirect_url'], '<') === 0) {
|
56
|
$redirect = trim($node->webform['redirect_url'], '<>');
|
57
|
// Redirection is set to front page.
|
58
|
if ($redirect == 'front') {
|
59
|
$redirect = 'url';
|
60
|
$redirect_url = $node->webform['redirect_url'];
|
61
|
}
|
62
|
else {
|
63
|
$redirect_url = '';
|
64
|
}
|
65
|
}
|
66
|
else {
|
67
|
$redirect = 'url';
|
68
|
$redirect_url = $node->webform['redirect_url'];
|
69
|
}
|
70
|
$form['submission']['redirection'] = array(
|
71
|
'#type' => 'item',
|
72
|
'#title' => t('Redirection location'),
|
73
|
'#theme' => 'webform_advanced_redirection_form',
|
74
|
'#description' => t('Choose where to redirect the user upon successful submission.') . ' ' . t('The <em>Custom URL</em> option supports Webform token replacements.') . ' ' . theme('webform_token_help', array('groups' => array('node', 'submission'))),
|
75
|
);
|
76
|
$form['submission']['redirection']['redirect']= array(
|
77
|
'#type' => 'radios',
|
78
|
'#default_value' => $redirect,
|
79
|
'#options' => array(
|
80
|
'confirmation' => t('Confirmation page'),
|
81
|
'url' => t('Custom URL'),
|
82
|
'none' => t('No redirect (reload current page)'),
|
83
|
),
|
84
|
'#parents' => array('redirect'),
|
85
|
);
|
86
|
$form['submission']['redirection']['redirect_url'] = array(
|
87
|
'#type' => 'textfield',
|
88
|
'#title' => t('Redirect URL'),
|
89
|
'#description' => t('URL to redirect the user to upon successful submission.'),
|
90
|
'#default_value' => $redirect_url,
|
91
|
'#maxlength' => 2048,
|
92
|
'#parents' => array('redirect_url'),
|
93
|
'#attributes' => array('title' => t('Custom URL value')),
|
94
|
);
|
95
|
|
96
|
// Submission limit settings for all submissions.
|
97
|
$form['submission']['total_submit_limit'] = array(
|
98
|
'#type' => 'item',
|
99
|
'#title' => t('Total submissions limit'),
|
100
|
'#theme' => 'webform_advanced_total_submit_limit_form',
|
101
|
'#description' => t('Limit the total number of allowed submissions.'),
|
102
|
);
|
103
|
$form['submission']['total_submit_limit']['enforce_total_limit'] = array(
|
104
|
'#type' => 'radios',
|
105
|
'#options' => array('no' => t('Unlimited'), 'yes' => 'Limit to !count total submission(s) !timespan'),
|
106
|
'#default_value' => $node->webform['total_submit_limit'] == -1 ? 'no' : 'yes',
|
107
|
'#parents' => array('enforce_total_limit'),
|
108
|
);
|
109
|
$form['submission']['total_submit_limit']['total_submit_limit'] = array(
|
110
|
'#type' => 'textfield',
|
111
|
'#maxlength' => 8,
|
112
|
'#size' => 8,
|
113
|
'#default_value' => $node->webform['total_submit_limit'] != -1 ? $node->webform['total_submit_limit'] : '',
|
114
|
'#parents' => array('total_submit_limit'),
|
115
|
);
|
116
|
$interval_options = array(
|
117
|
'-1' => t('ever'),
|
118
|
'60' => t('every minute'),
|
119
|
'300' => t('every 5 minutes'),
|
120
|
'3600' => t('every hour'),
|
121
|
'86400' => t('every day'),
|
122
|
'604800' => t('every week'),
|
123
|
);
|
124
|
$form['submission']['total_submit_limit']['total_submit_interval'] = array(
|
125
|
'#type' => 'select',
|
126
|
'#options' => $interval_options,
|
127
|
'#default_value' => $node->webform['total_submit_interval'],
|
128
|
'#parents' => array('total_submit_interval'),
|
129
|
);
|
130
|
|
131
|
// Submission limit per user settings.
|
132
|
$form['submission']['submit_limit'] = array(
|
133
|
'#type' => 'item',
|
134
|
'#title' => t('Per user submission limit'),
|
135
|
'#theme' => 'webform_advanced_submit_limit_form',
|
136
|
'#description' => t('Limit the number of submissions <em>per user</em>. A user is identified by their user login if logged-in, or by their IP Address and Cookie if anonymous. Use of cookies may be modified in the global <a href="!url">Webform settings</a>.', array('!url' => url('admin/config/content/webform'))),
|
137
|
);
|
138
|
$form['submission']['submit_limit']['enforce_limit'] = array(
|
139
|
'#type' => 'radios',
|
140
|
'#options' => array('no' => t('Unlimited'), 'yes' => 'Limit each user to !count submission(s) !timespan'),
|
141
|
'#default_value' => $node->webform['submit_limit'] == -1 ? 'no' : 'yes',
|
142
|
'#parents' => array('enforce_limit'),
|
143
|
);
|
144
|
$form['submission']['submit_limit']['submit_limit'] = array(
|
145
|
'#type' => 'textfield',
|
146
|
'#maxlength' => 2,
|
147
|
'#size' => 2,
|
148
|
'#default_value' => $node->webform['submit_limit'] != -1 ? $node->webform['submit_limit'] : '',
|
149
|
'#parents' => array('submit_limit'),
|
150
|
);
|
151
|
$form['submission']['submit_limit']['submit_interval'] = array(
|
152
|
'#type' => 'select',
|
153
|
'#options' => $interval_options,
|
154
|
'#default_value' => $node->webform['submit_interval'],
|
155
|
'#parents' => array('submit_interval'),
|
156
|
);
|
157
|
|
158
|
$form['submission']['status'] = array(
|
159
|
'#type' => 'radios',
|
160
|
'#title' => t('Status of this form'),
|
161
|
'#default_value' => $node->webform['status'] == 0 ? 0 : 1,
|
162
|
'#description' => t('Closing a form prevents any further submissions by any users.'),
|
163
|
'#parents' => array('status'),
|
164
|
'#options' => array(1 => t('Open'), 0 => t('Closed')),
|
165
|
);
|
166
|
/* End Edit Form */
|
167
|
|
168
|
/* Start per-role submission control */
|
169
|
$form['role_control'] = array(
|
170
|
'#type' => 'fieldset',
|
171
|
'#title' => t('Submission access'),
|
172
|
'#collapsible' => TRUE,
|
173
|
'#collapsed' => FALSE,
|
174
|
'#description' => t('These permissions affect which roles can submit this webform. It does not prevent access to the webform page. If needing to prevent access to the webform page entirely, use a content access module such as <a href="http://drupal.org/project/taxonomy_access">Taxonomy Access</a> or <a href="http://drupal.org/project/node_privacy_byrole">Node Privacy by Role</a>.'),
|
175
|
'#access' => webform_variable_get('webform_submission_access_control'),
|
176
|
'#weight' => 10,
|
177
|
'#states' => array(
|
178
|
'invisible' => array(
|
179
|
':input[name="confidential"]' => array('checked' => TRUE),
|
180
|
),
|
181
|
),
|
182
|
);
|
183
|
$user_roles = user_roles();
|
184
|
foreach ($user_roles as $rid => $rname) {
|
185
|
if ($rid == DRUPAL_ANONYMOUS_RID || $rid == DRUPAL_AUTHENTICATED_RID) {
|
186
|
continue;
|
187
|
}
|
188
|
$user_roles[$rid] = webform_tt("user:rid:$rid:name", $rname);
|
189
|
}
|
190
|
$form['role_control']['roles'] = array(
|
191
|
'#default_value' => $node->webform['roles'],
|
192
|
'#options' => $user_roles,
|
193
|
'#type' => 'checkboxes',
|
194
|
'#title' => t('Roles that can submit this webform'),
|
195
|
'#description' => t('The %authenticated role applies to any user signed into the site, regardless of other assigned roles.', array('%authenticated' => $user_roles[2])),
|
196
|
);
|
197
|
/* End per-role submission control */
|
198
|
|
199
|
/* Start progress bar settings form */
|
200
|
$form['progressbar'] = array(
|
201
|
'#type' => 'fieldset',
|
202
|
'#title' => t('Progress bar'),
|
203
|
'#collapsible' => TRUE,
|
204
|
'#collapsed' => TRUE,
|
205
|
'#weight' => 15,
|
206
|
);
|
207
|
$progress_bar_style = array_filter(array(
|
208
|
$node->webform['progressbar_page_number'] ? 'progressbar_page_number' : NULL,
|
209
|
$node->webform['progressbar_percent'] ? 'progressbar_percent' : NULL,
|
210
|
$node->webform['progressbar_bar'] ? 'progressbar_bar' : NULL,
|
211
|
$node->webform['progressbar_pagebreak_labels'] ? 'progressbar_pagebreak_labels' : NULL,
|
212
|
$node->webform['progressbar_include_confirmation'] ? 'progressbar_include_confirmation' : NULL,
|
213
|
));
|
214
|
$form['progressbar']['webform_progressbar_style'] = array(
|
215
|
'#type' => 'checkboxes',
|
216
|
'#title' => t('Progress bar style'),
|
217
|
'#options' => array(
|
218
|
'progressbar_bar' => t('Show progress bar'),
|
219
|
'progressbar_page_number' => t('Show page number as number of completed (i.e. Page 1 of 10)'),
|
220
|
'progressbar_percent' => t('Show percentage completed (i.e. 10%)'),
|
221
|
'progressbar_pagebreak_labels' => t('Show page labels from page break components'),
|
222
|
'progressbar_include_confirmation' => t('Include confirmation page in progress bar'),
|
223
|
),
|
224
|
'#default_value' => $progress_bar_style,
|
225
|
'#description' => t('Choose how the progress bar should be displayed for multi-page forms.'),
|
226
|
);
|
227
|
$form['progressbar']['progressbar_label_first'] = array(
|
228
|
'#type' => 'textfield',
|
229
|
'#title' => t('First page label'),
|
230
|
'#default_value' => $node->webform['progressbar_label_first'],
|
231
|
'#maxlength' => 255,
|
232
|
'#description' => t('The first page label in the progress bar. Subseqent pages are titled by their page break label.'),
|
233
|
'#states' => array(
|
234
|
'visible' => array(
|
235
|
':input[name="webform_progressbar_style[progressbar_pagebreak_labels]"]' => array('checked' => TRUE),
|
236
|
),
|
237
|
),
|
238
|
);
|
239
|
$form['progressbar']['progressbar_label_confirmation'] = array(
|
240
|
'#type' => 'textfield',
|
241
|
'#title' => t('Confirmation page label'),
|
242
|
'#default_value' => $node->webform['progressbar_label_confirmation'],
|
243
|
'#maxlength' => 255,
|
244
|
'#states' => array(
|
245
|
'visible' => array(
|
246
|
':input[name="webform_progressbar_style[progressbar_pagebreak_labels]"]' => array('checked' => TRUE),
|
247
|
':input[name="webform_progressbar_style[progressbar_include_confirmation]"]' => array('checked' => TRUE),
|
248
|
),
|
249
|
),
|
250
|
);
|
251
|
/* End progress bar settings form */
|
252
|
|
253
|
/* Preview page settings form */
|
254
|
$form['preview'] = array(
|
255
|
'#type' => 'fieldset',
|
256
|
'#title' => t('Preview page'),
|
257
|
'#collapsible' => TRUE,
|
258
|
'#collapsed' => TRUE,
|
259
|
'#weight' => 18,
|
260
|
'#id' => 'webform-preview-fieldset',
|
261
|
);
|
262
|
|
263
|
$form['preview']['preview'] = array(
|
264
|
'#type' => 'checkbox',
|
265
|
'#title' => t('Enable preview page'),
|
266
|
'#description' => t('Add a page for previewing the form before submitting.'),
|
267
|
'#default_value' => $node->webform['preview'],
|
268
|
'#id' => 'webform-preview-enable'
|
269
|
);
|
270
|
$form['preview']['settings'] = array(
|
271
|
'#type' => 'container',
|
272
|
'#states' => array(
|
273
|
'visible' => array(
|
274
|
'#webform-preview-enable' => array('checked' => TRUE),
|
275
|
),
|
276
|
),
|
277
|
'#id' => 'webform-preview-settings',
|
278
|
'#theme_wrappers' => array('container'),
|
279
|
);
|
280
|
$form['preview']['settings']['preview_title'] = array(
|
281
|
'#type' => 'textfield',
|
282
|
'#title' => t('Preview page title'),
|
283
|
'#default_value' => $node->webform['preview_title'],
|
284
|
'#description' => t('The page title will be used in the progress bar (if enabled). If left blank, the default title %preview will be used.', array('%preview' => t('Preview'))),
|
285
|
);
|
286
|
$form['preview']['settings']['preview_next_button_label'] = array(
|
287
|
'#type' => 'textfield',
|
288
|
'#title' => t('Preview button label'),
|
289
|
'#default_value' => $node->webform['preview_next_button_label'],
|
290
|
'#description' => t('The text for the button that will proceed to the preview page. If left blank, the default label %preview will be used.', array('%preview' => t('Preview'))),
|
291
|
'#size' => 20,
|
292
|
);
|
293
|
$form['preview']['settings']['preview_prev_button_label'] = array(
|
294
|
'#type' => 'textfield',
|
295
|
'#title' => t('Previous page button label'),
|
296
|
'#default_value' => $node->webform['preview_prev_button_label'],
|
297
|
'#description' => t('The text for the button to go backwards from the preview page. If left blank, the default label %previous will be used.', array('%previous' => t('< Previous'))),
|
298
|
'#size' => 20,
|
299
|
);
|
300
|
$submit_button_text = $node->webform['submit_text'] ? t($node->webform['submit_text']) : t('Submit');
|
301
|
$preview_default_message = t('Please review your submission. Your submission is not complete until you press the "@button" button!', array('@button' => $submit_button_text));
|
302
|
$form['preview']['settings']['preview_message'] = array(
|
303
|
'#type' => 'text_format',
|
304
|
'#title' => t('Preview message'),
|
305
|
'#default_value' => $node->webform['preview_message'],
|
306
|
'#format' => $node->webform['preview_message_format'],
|
307
|
'#description' => t('A message to be displayed on the preview page. If left blank, the message "!default" will be used. Supports Webform token replacements.', array('!default' => $preview_default_message)) . ' ' . theme('webform_token_help', array('groups' => array('node', 'submission'))),
|
308
|
);
|
309
|
$form['preview']['settings']['preview_components'] = array(
|
310
|
'#type' => 'select',
|
311
|
'#title' => t('Included preview values'),
|
312
|
'#options' => webform_component_list($node, 'email', TRUE),
|
313
|
'#default_value' => array_diff(array_keys($node->webform['components']), $node->webform['preview_excluded_components']),
|
314
|
'#multiple' => TRUE,
|
315
|
'#size' => 10,
|
316
|
'#description' => t('If you wish to include only parts of the submission in the preview, select the components that should be included.'),
|
317
|
'#process' => array('webform_component_select'),
|
318
|
);
|
319
|
/* End preview page settings form */
|
320
|
|
321
|
/* Start advanced settings form */
|
322
|
$form['advanced'] = array(
|
323
|
'#type' => 'fieldset',
|
324
|
'#title' => t('Advanced settings'),
|
325
|
'#collapsible' => TRUE,
|
326
|
'#collapsed' => TRUE,
|
327
|
'#weight' => 20,
|
328
|
);
|
329
|
$form['advanced']['block'] = array(
|
330
|
'#type' => 'checkbox',
|
331
|
'#title' => t('Available as block'),
|
332
|
'#default_value' => $node->webform['block'],
|
333
|
'#description' => t('If enabled this webform will be available as a block.'),
|
334
|
'#access' => user_access('administer blocks') || user_access('administer site configuration') || user_access('use panels dashboard'),
|
335
|
);
|
336
|
$form['advanced']['allow_draft'] = array(
|
337
|
'#type' => 'checkbox',
|
338
|
'#title' => t('Show "Save draft" button'),
|
339
|
'#default_value' => $node->webform['allow_draft'],
|
340
|
'#description' => t('Allow your users to save and finish the form later. This option is available only for authenticated users.'),
|
341
|
);
|
342
|
$form['advanced']['auto_save'] = array(
|
343
|
'#type' => 'checkbox',
|
344
|
'#title' => t('Automatically save as draft between pages and when there are validation errors'),
|
345
|
'#default_value' => $node->webform['auto_save'],
|
346
|
'#description' => t('Automatically save partial submissions when users click the "Next" or "Previous" buttons in a multipage form or when validation errors prevent form submission.'),
|
347
|
);
|
348
|
$form['advanced']['submit_notice'] = array(
|
349
|
'#type' => 'checkbox',
|
350
|
'#title' => t('Show the notification about previous submissions'),
|
351
|
'#default_value' => $node->webform['submit_notice'],
|
352
|
'#description' => t('Show the previous submissions notification that appears when users have previously submitted this form.'),
|
353
|
);
|
354
|
$form['advanced']['confidential'] = array(
|
355
|
'#type' => 'checkbox',
|
356
|
'#title' => t('Confidential submissions'),
|
357
|
'#default_value' => $node->webform['confidential'],
|
358
|
'#description' => t('Confidential submissions have no recorded IP address and must be submitted while logged out.'),
|
359
|
);
|
360
|
$form['advanced']['submit_text'] = array(
|
361
|
'#type' => 'textfield',
|
362
|
'#title' => t('Submit button label'),
|
363
|
'#default_value' => $node->webform['submit_text'],
|
364
|
'#description' => t('By default the submit button on this form will have the label <em>Submit</em>. Enter a new title here to override the default.'),
|
365
|
'#size' => 20,
|
366
|
);
|
367
|
$form['advanced']['next_serial'] = array(
|
368
|
'#type' => 'textfield',
|
369
|
'#title' => t('Next submission number'),
|
370
|
'#default_value' => $node->webform['next_serial'],
|
371
|
'#description' => t('The value of the next submission number. This is usually 1 when you start and will go up with each form submission.'),
|
372
|
'#size' => 8,
|
373
|
'#maxlength' => 8,
|
374
|
);
|
375
|
/* End Advanced Settings Form */
|
376
|
|
377
|
$form['actions'] = array(
|
378
|
'#type' => 'actions',
|
379
|
'#weight' => 300,
|
380
|
);
|
381
|
|
382
|
$form['actions']['submit'] = array(
|
383
|
'#type' => 'submit',
|
384
|
'#value' => t('Save configuration'),
|
385
|
);
|
386
|
|
387
|
return $form;
|
388
|
}
|
389
|
|
390
|
/**
|
391
|
* Validate handler for webform_configure_form().
|
392
|
*/
|
393
|
function webform_configure_form_validate($form, &$form_state) {
|
394
|
// Ensure the entered redirect URL is valid.
|
395
|
if ($form_state['values']['redirect'] == 'url') {
|
396
|
$redirect_url = trim($form_state['values']['redirect_url']);
|
397
|
if (empty($redirect_url)) {
|
398
|
form_error($form['submission']['redirection']['redirect_url'], t('A valid URL is required for custom redirection.'));
|
399
|
}
|
400
|
elseif (strpos($redirect_url, 'http') === 0 && !valid_url(webform_replace_tokens($redirect_url, $form['#node']), TRUE)) {
|
401
|
form_error($form['submission']['redirection']['redirect_url'], t('The entered URL is not a valid address.'));
|
402
|
}
|
403
|
else {
|
404
|
form_set_value($form['submission']['redirection']['redirect_url'], $redirect_url, $form_state);
|
405
|
}
|
406
|
}
|
407
|
elseif ($form_state['values']['redirect'] == 'confirmation') {
|
408
|
form_set_value($form['submission']['redirection']['redirect_url'], '<confirmation>', $form_state);
|
409
|
}
|
410
|
else {
|
411
|
form_set_value($form['submission']['redirection']['redirect_url'], '<none>', $form_state);
|
412
|
}
|
413
|
|
414
|
// Ensure only positive integers are entered as submission limits.
|
415
|
foreach (array('total_submit_limit' => 'enforce_total_limit', 'submit_limit' => 'enforce_limit') as $field => $enforce_fk) {
|
416
|
$limit = $form['submission'][$field][$field]['#value'];
|
417
|
if ($form['submission'][$field][$enforce_fk]['#value'] !== 'no' && $limit !== '' && (int) $limit < 1 && (int) $limit !== -1) {
|
418
|
form_error($form['submission'][$field][$field], t('The submission limit must be at least 1.'));
|
419
|
}
|
420
|
}
|
421
|
|
422
|
// Prohibit the combination of confidential + per-user limit + ip-only
|
423
|
// submission tracking for anonymous users as it would not be enforceable.
|
424
|
if (webform_variable_get('webform_tracking_mode') == 'ip_address' &&
|
425
|
$form_state['values']['confidential'] &&
|
426
|
$form_state['values']['enforce_limit'] == 'yes') {
|
427
|
// Note that FAPI doesn't actually support error highlighting on radio or
|
428
|
// checkbox form elements.
|
429
|
form_error($form['advanced']['confidential'],
|
430
|
t('Choose a "Per user submission limit" or "Confidential submissions", but not both. Or ask the adminstrator to track anonymous users by cookie, rather than IP address only.'));
|
431
|
}
|
432
|
}
|
433
|
|
434
|
/**
|
435
|
* Submit handler for webform_configure_form().
|
436
|
*/
|
437
|
function webform_configure_form_submit($form, &$form_state) {
|
438
|
// Edit the node by reference just to shorten it up.
|
439
|
$node = &$form['#node'];
|
440
|
|
441
|
// Save the confirmation.
|
442
|
$node->webform['confirmation'] = $form_state['values']['confirmation']['value'];
|
443
|
$node->webform['confirmation_format'] = $form_state['values']['confirmation']['format'];
|
444
|
|
445
|
// Save the redirect URL
|
446
|
$node->webform['redirect_url'] = $form_state['values']['redirect_url'];
|
447
|
|
448
|
// Overall form status.
|
449
|
$node->webform['status'] = $form_state['values']['status'];
|
450
|
|
451
|
// Save roles.
|
452
|
$node->webform['roles'] = array_keys(array_filter($form_state['values']['roles']));
|
453
|
|
454
|
// Set the block option.
|
455
|
$node->webform['block'] = $form_state['values']['block'];
|
456
|
|
457
|
// Set the draft option.
|
458
|
$node->webform['allow_draft'] = $form_state['values']['allow_draft'];
|
459
|
|
460
|
// Set the auto-save draft option.
|
461
|
$node->webform['auto_save'] = $form_state['values']['auto_save'];
|
462
|
|
463
|
// Set the submit limit to -1 if set to unlimited.
|
464
|
if ($form_state['values']['enforce_limit'] == 'no') {
|
465
|
$node->webform['submit_limit'] = -1;
|
466
|
$node->webform['submit_interval'] = -1;
|
467
|
}
|
468
|
else {
|
469
|
$node->webform['submit_limit'] = (int) $form_state['values']['submit_limit'];
|
470
|
$node->webform['submit_interval'] = (int) $form_state['values']['submit_interval'];
|
471
|
}
|
472
|
|
473
|
// Set the total submit limit to -1 if set to unlimited.
|
474
|
if ($form_state['values']['enforce_total_limit'] == 'no') {
|
475
|
$node->webform['total_submit_limit'] = -1;
|
476
|
$node->webform['total_submit_interval'] = -1;
|
477
|
}
|
478
|
else {
|
479
|
$node->webform['total_submit_limit'] = (int) $form_state['values']['total_submit_limit'];
|
480
|
$node->webform['total_submit_interval'] = (int) $form_state['values']['total_submit_interval'];
|
481
|
}
|
482
|
|
483
|
// Set the progress bar preferences.
|
484
|
$progress_bar_settings = array_filter($form_state['values']['webform_progressbar_style']);
|
485
|
$node->webform['progressbar_page_number'] = in_array('progressbar_page_number', $progress_bar_settings);
|
486
|
$node->webform['progressbar_percent'] = in_array('progressbar_percent', $progress_bar_settings);
|
487
|
$node->webform['progressbar_bar'] = in_array('progressbar_bar', $progress_bar_settings);
|
488
|
$node->webform['progressbar_pagebreak_labels'] = in_array('progressbar_pagebreak_labels', $progress_bar_settings);
|
489
|
$node->webform['progressbar_include_confirmation'] = in_array('progressbar_include_confirmation', $progress_bar_settings);
|
490
|
$node->webform['progressbar_label_first'] = $form_state['values']['progressbar_label_first'];
|
491
|
$node->webform['progressbar_label_confirmation'] = $form_state['values']['progressbar_label_confirmation'];
|
492
|
|
493
|
// Set the preview settings.
|
494
|
$node->webform['preview'] = (int) $form_state['values']['preview'];
|
495
|
$node->webform['preview_next_button_label'] = $form_state['values']['preview_next_button_label'];
|
496
|
$node->webform['preview_prev_button_label'] = $form_state['values']['preview_prev_button_label'];
|
497
|
$node->webform['preview_title'] = $form_state['values']['preview_title'];
|
498
|
$node->webform['preview_message'] = $form_state['values']['preview_message']['value'];
|
499
|
$node->webform['preview_message_format'] = $form_state['values']['preview_message']['format'];
|
500
|
|
501
|
// Save the list of included preview components.
|
502
|
// We actually maintain an *exclusion* list, so any new components will
|
503
|
// default to being included in the preview until unchecked.
|
504
|
$included = array_keys(array_filter((array) $form_state['values']['preview_components']));
|
505
|
$excluded = array_diff(array_keys($node->webform['components']), $included);
|
506
|
$node->webform['preview_excluded_components'] = $excluded;
|
507
|
|
508
|
// Set submit notice.
|
509
|
$node->webform['submit_notice'] = $form_state['values']['submit_notice'];
|
510
|
|
511
|
// Set confidential.
|
512
|
$node->webform['confidential'] = $form_state['values']['confidential'];
|
513
|
|
514
|
// Set submit button text.
|
515
|
$node->webform['submit_text'] = $form_state['values']['submit_text'];
|
516
|
|
517
|
// Set next serial number. It must be a positive integer greater than any
|
518
|
// existing serial number, which could have increased while this form was
|
519
|
// being edited.
|
520
|
$next_min = _webform_submission_serial_next_value_used($node->nid);
|
521
|
$next_serial = (int)$form_state['values']['next_serial'];
|
522
|
if ($next_serial < $next_min) {
|
523
|
drupal_set_message(t('The next submission number was increased to @min to make it higher than existing submissions.',
|
524
|
array('@min' => $next_min)));
|
525
|
$next_serial = $next_min;
|
526
|
}
|
527
|
$node->webform['next_serial'] = $next_serial;
|
528
|
}
|
529
|
|
530
|
/**
|
531
|
* Submit handler for webform_configure_form() that saves the node.
|
532
|
*
|
533
|
* This is separate from webform_configure_form_submit() to allow other modules
|
534
|
* to add properties if needed into the $form['#node'] object before save.
|
535
|
*/
|
536
|
function webform_configure_form_submit_save($form, &$form_state) {
|
537
|
node_save($form['#node']);
|
538
|
drupal_set_message(t('The form settings have been updated.'));
|
539
|
|
540
|
$node = &$form['#node'];
|
541
|
if (!$node->webform['block'] && function_exists('block_load') &&
|
542
|
($block = block_load('webform', 'client-block-' . $node->nid)) &&
|
543
|
!empty($block->bid)) {
|
544
|
// An existing block for this not-currently-available block was already configured.
|
545
|
// See https://www.drupal.org/node/2365825
|
546
|
// The core block module contains a bug which causes it to not remove blocks
|
547
|
// which are no longer available in code. Therefore, to prevent the block from
|
548
|
// being processed, it must be removed manually here.
|
549
|
// Remove the block for all themes.
|
550
|
db_delete('block')
|
551
|
->condition('module', 'webform')
|
552
|
->condition('delta', $block->delta)
|
553
|
->execute();
|
554
|
// Remove any roles associated with the block
|
555
|
db_delete('block_role')
|
556
|
->condition('module', 'webform')
|
557
|
->condition('delta', $block->delta)
|
558
|
->execute();
|
559
|
drupal_set_message(t('The block %info was deleted.', array('%info' => t('Webform: !title', array('!title' => $node->title)))));
|
560
|
cache_clear_all();
|
561
|
}
|
562
|
}
|
563
|
|
564
|
/**
|
565
|
* Theme the redirection setting on the webform node form.
|
566
|
*/
|
567
|
function theme_webform_advanced_redirection_form($variables) {
|
568
|
$form = $variables['form'];
|
569
|
// Add special class for setting the active radio button.
|
570
|
$form['redirect_url']['#attributes']['class'][] = 'webform-set-active';
|
571
|
|
572
|
// Remove wrappers around the inline Redirect URL field.
|
573
|
$form['redirect_url']['#theme_wrappers'] = array();
|
574
|
|
575
|
$form['redirect']['confirmation']['#theme_wrappers'] = array('webform_inline_radio');
|
576
|
$form['redirect']['url']['#theme_wrappers'] = array('webform_inline_radio');
|
577
|
$form['redirect']['none']['#theme_wrappers'] = array('webform_inline_radio');
|
578
|
$form['redirect']['url']['#title'] = t('Custom URL: !redirect_url', array('!redirect_url' => drupal_render($form['redirect_url'])));
|
579
|
|
580
|
return drupal_render_children($form);
|
581
|
}
|
582
|
|
583
|
/**
|
584
|
* Theme the submit limit fieldset on the webform node form.
|
585
|
*/
|
586
|
function theme_webform_advanced_submit_limit_form($variables) {
|
587
|
$form = $variables['form'];
|
588
|
$form['submit_limit']['#attributes']['class'][] = 'webform-set-active';
|
589
|
$form['submit_interval']['#attributes']['class'][] = 'webform-set-active';
|
590
|
// Remove div wrappers around limit options.
|
591
|
$form['submit_limit']['#theme_wrappers'] = array();
|
592
|
$form['submit_interval']['#theme_wrappers'] = array();
|
593
|
|
594
|
$form['enforce_limit']['no']['#theme_wrappers'] = array('webform_inline_radio');
|
595
|
$form['enforce_limit']['yes']['#theme_wrappers'] = array('webform_inline_radio');
|
596
|
$form['enforce_limit']['yes']['#title'] = t('Limit each user to !count submission(s) !timespan', array('!count' => drupal_render($form['submit_limit']), '!timespan' => drupal_render($form['submit_interval'])));
|
597
|
|
598
|
return drupal_render_children($form);
|
599
|
}
|
600
|
|
601
|
/**
|
602
|
* Theme the total submit limit fieldset on the webform node form.
|
603
|
*/
|
604
|
function theme_webform_advanced_total_submit_limit_form($variables) {
|
605
|
$form = $variables['form'];
|
606
|
$form['total_submit_limit']['#attributes']['class'][] = 'webform-set-active';
|
607
|
$form['total_submit_interval']['#attributes']['class'][] = 'webform-set-active';
|
608
|
// Remove div wrappers around limit options.
|
609
|
$form['total_submit_limit']['#theme_wrappers'] = array();
|
610
|
$form['total_submit_interval']['#theme_wrappers'] = array();
|
611
|
|
612
|
$form['enforce_total_limit']['no']['#theme_wrappers'] = array('webform_inline_radio');
|
613
|
$form['enforce_total_limit']['yes']['#theme_wrappers'] = array('webform_inline_radio');
|
614
|
$form['enforce_total_limit']['yes']['#title'] = t('Limit to !count total submission(s) !timespan', array('!count' => drupal_render($form['total_submit_limit']), '!timespan' => drupal_render($form['total_submit_interval'])));
|
615
|
|
616
|
return drupal_render_children($form);
|
617
|
}
|