-
Notifications
You must be signed in to change notification settings - Fork 22
/
form_settings.php
1454 lines (1274 loc) · 44.6 KB
/
form_settings.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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
if ( ! class_exists( 'GFForms' ) ) {
die();
}
use Gravity_Forms\Gravity_Forms\Settings\Settings;
/**
* Class GFFormSettings
*
* Handles the form settings page.
*
* @since Unknown
*/
class GFFormSettings {
/**
* Stores the current instance of the Settings renderer.
*
* @since 2.5
*
* @var false|Gravity_Forms\Gravity_Forms\Settings\Settings
*/
private static $_settings_renderer = false;
/**
* Determines which form settings page to display.
*
* @since Unknown
*
* @return void
*/
public static function form_settings_page() {
$subview = rgget( 'subview' ) ? rgget( 'subview' ) : 'settings';
switch ( $subview ) {
case 'settings':
self::form_settings_ui();
break;
case 'confirmation':
require_once( 'includes/class-confirmation.php' );
self::page_header( __( 'Confirmations', 'gravityforms' ) );
GF_Confirmation::render_page();
self::page_footer();
break;
case 'notification':
self::notification_page();
break;
case 'personal-data':
self::personal_data_page();
break;
default:
/**
* Fires when the settings page view is determined
*
* Used to add additional pages to the form settings
*
* @since Unknown
*
* @param string $subview Used to complete the action name, allowing an additional subview to be detected
*/
do_action( "gform_form_settings_page_{$subview}" );
}
}
/**
* Displays the form settings UI.
*
* @since Unknown
*
* @return void
*/
public static function form_settings_ui() {
$form_id = rgget( 'id' );
// Form ID isn't valid (it's either deleted or just not an existing form ID)
if ( ! GFAPI::form_id_exists( $form_id ) ) {
GFCommon::log_error( __METHOD__ . '(): Invalid Form ID: ' . $form_id );
wp_die( 'Invalid Form ID' );
}
self::page_header();
if ( ! self::get_settings_renderer() ) {
self::initialize_settings_renderer();
}
self::get_settings_renderer()->render();
self::page_footer();
}
/**
* Prepare form settings fields.
*
* @since 2.5
*
* @param array $form Form being edited.
*
* @return array
*/
public static function form_settings_fields( $form ) {
$fields = array(
'form_basics' => array(
'title' => esc_html__( 'Form Basics', 'gravityforms' ),
'fields' => array(
array(
'name' => 'title',
'type' => 'text',
'label' => esc_html__( 'Form Title', 'gravityforms' ),
'tooltip' => gform_tooltip( 'form_title', '', true ),
'required' => true,
'validation_callback' => function( $field, $value ) use ( $form ) {
// If value is empty, set error.
if ( rgblank( $value ) ) {
$field->set_error( rgobj( $field, 'error_message' ) );
return;
}
// Get forms.
$forms = GFFormsModel::get_forms();
// Loop through forms, look for duplicate title.
foreach ( $forms as $f ) {
// If form does not have a duplicate title, skip.
if ( strtolower( $f->title ) !== strtolower( $value ) ) {
continue;
}
// If form ID matches, skip.
if ( (int) $form['id'] === (int) $f->id ) {
continue;
}
// Set field error.
$field->set_error( esc_html__( 'The form title you have entered has already been used. Please enter a unique form title.', 'gravityforms' ) );
return;
}
$field->do_validation( $value );
},
),
array(
'name' => 'description',
'type' => 'textarea',
'label' => esc_html__( 'Form Description', 'gravityforms' ),
'tooltip' => gform_tooltip( 'form_description', '', true ),
'allow_html' => true,
),
),
),
'form_layout' => array(
'title' => esc_html__( 'Form Layout', 'gravityforms' ),
'fields' => array(
array(
'name' => 'labelPlacement',
'type' => 'select',
'label' => esc_html__( 'Label Placement', 'gravityforms' ),
'default_value' => 'top_label',
'tooltip' => gform_tooltip( 'form_label_placement', '', true ),
'choices' => array(
array(
'label' => __( 'Top aligned', 'gravityforms' ),
'value' => 'top_label',
),
array(
'label' => __( 'Left aligned', 'gravityforms' ),
'value' => 'left_label',
),
array(
'label' => __( 'Right aligned', 'gravityforms' ),
'value' => 'right_label',
),
),
),
array(
'name' => 'descriptionPlacement',
'type' => 'select',
'label' => esc_html__( 'Description Placement', 'gravityforms' ),
'default_value' => 'below',
'tooltip' => gform_tooltip( 'form_description_placement', '', true ),
'dependency' => array(
'live' => true,
'fields' => array(
array(
'field' => 'labelPlacement',
'values' => array( 'top_label' ),
),
),
),
'choices' => array(
array(
'label' => __( 'Below inputs', 'gravityforms' ),
'value' => 'below',
),
array(
'label' => __( 'Above inputs', 'gravityforms' ),
'value' => 'above',
),
),
),
array(
'name' => 'validationPlacement',
'type' => 'select',
'label' => esc_html__( 'Validation Message Placement', 'gravityforms' ),
'default_value' => 'below',
'tooltip' => gform_tooltip( 'form_validation_placement', '', true ),
'choices' => array(
array(
'label' => __( 'Below inputs', 'gravityforms' ),
'value' => 'below',
),
array(
'label' => __( 'Above inputs', 'gravityforms' ),
'value' => 'above',
),
),
),
array(
'name' => 'subLabelPlacement',
'type' => 'select',
'label' => esc_html__( 'Sub-Label Placement', 'gravityforms' ),
'tooltip' => gform_tooltip( 'form_sub_label_placement', '', true ),
'choices' => array(
array(
'label' => __( 'Below inputs', 'gravityforms' ),
'value' => 'below',
),
array(
'label' => __( 'Above inputs', 'gravityforms' ),
'value' => 'above',
),
),
),
array(
'name' => 'validationSummary',
'type' => 'toggle',
'label' => esc_html__( 'Validation Summary', 'gravityforms' ),
'default_value' => false,
'tooltip' => gform_tooltip( 'validation_summary', '', true ),
),
array(
'name' => 'requiredIndicator',
'label' => esc_html__( 'Required Field Indicator', 'gravityforms' ),
'type' => 'radio',
'default_value' => ( GFCommon::is_legacy_markup_enabled( $form ) ) ? 'asterisk' : 'text',
'horizontal' => true,
'tooltip' => gform_tooltip( 'form_required_indicator', '', true ),
'choices' => array(
array(
'label' => esc_html__( 'Text: (Required)', 'gravityforms' ),
'value' => 'text',
),
array(
'label' => esc_html__( 'Asterisk: *', 'gravityforms' ),
'value' => 'asterisk',
),
array(
'label' => esc_html__( 'Custom:', 'gravityforms' ),
'value' => 'custom',
),
),
),
array(
'name' => 'customRequiredIndicator',
'type' => 'text',
'label' => esc_html__( 'Custom Required Indicator', 'gravityforms' ),
'default_value' => esc_html__( '(Required)', 'gravityforms' ),
'dependency' => array(
'live' => true,
'fields' => array(
array(
'field' => 'requiredIndicator',
'values' => array( 'custom' ),
),
),
),
),
array(
'name' => 'cssClass',
'type' => 'text',
'label' => esc_html__( 'CSS Class Name', 'gravityforms' ),
'tooltip' => gform_tooltip( 'form_css_class', '', true ),
),
),
),
'form_button' => array(
'title' => esc_html__( 'Form Button', 'gravityforms' ),
'fields' => array(
array(
'name' => 'deprecated',
'type' => 'html',
'html' => esc_html__( 'Form button settings are now located in the form editor! To edit the button settings, go to the form editor and click on the submit button.', 'gravityforms' ),
),
),
),
'save_and_continue' => array(
'title' => esc_html__( 'Save and Continue', 'gravityforms' ),
'fields' => array(
array(
'name' => 'saveEnabled',
'type' => 'toggle',
'label' => __( 'Enable Save and Continue', 'gravityforms' ),
),
array(
'name' => 'saveButtonText',
'type' => 'text',
'label' => esc_html__( 'Link Text', 'gravityforms' ),
'default_value' => __( 'Save & Continue', 'gravityforms' ),
'dependency' => array(
'live' => true,
'fields' => array(
array(
'field' => 'saveEnabled',
),
),
),
'description' => sprintf(
'<div class="alert warning"><p>%s</p><p>%s</p></div>',
esc_html( 'This feature stores potentially private and sensitive data on this server and protects it with a unique link which is displayed to the user on the page in plain, unencrypted text. The link is similar to a password so it\'s strongly advisable to ensure that the page enforces a secure connection (HTTPS) before activating this setting.', 'gravityforms' ),
esc_html( 'When this setting is activated two confirmations and one notification are automatically generated and can be modified in their respective editors. When this setting is deactivated the confirmations and the notification will be deleted automatically and any modifications will be lost.', 'gravityforms' )
),
),
),
),
'restrictions' => array(
'title' => esc_html__( 'Restrictions', 'gravityforms' ),
'fields' => array(
array(
'name' => 'limitEntries',
'type' => 'checkbox',
'label' => __( 'Limit number of entries', 'gravityforms' ),
'tooltip' => gform_tooltip( 'form_limit_entries', '', true ),
'choices' => array(
array(
'name' => 'limitEntries',
'label' => __( 'Enable entry limit', 'gravityforms' ),
),
),
'fields' => array(
array(
'name' => 'limitEntriesNumber',
'type' => 'text_and_select',
'label' => __( 'Number of Entries', 'gravityforms' ),
'dependency' => array(
'live' => true,
'fields' => array(
array(
'field' => 'limitEntries',
),
),
),
'inputs' => array(
'text' => array(
'name' => 'limitEntriesCount',
'input_type' => 'number',
),
'select' => array(
'name' => 'limitEntriesPeriod',
'choices' => array(
array(
'label' => __( 'total entries', 'gravityforms' ),
'value' => '',
),
array(
'label' => __( 'per day', 'gravityforms' ),
'value' => 'day',
),
array(
'label' => __( 'per week', 'gravityforms' ),
'value' => 'week',
),
array(
'label' => __( 'per month', 'gravityforms' ),
'value' => 'month',
),
array(
'label' => __( 'per year', 'gravityforms' ),
'value' => 'year',
),
),
),
),
),
array(
'name' => 'limitEntriesMessage',
'type' => 'textarea',
'label' => esc_html__( 'Entry Limit Reached Message', 'gravityforms' ),
'allow_html' => true,
'dependency' => array(
'live' => true,
'fields' => array(
array(
'field' => 'limitEntries',
),
),
),
),
),
),
array(
'name' => 'scheduleForm',
'type' => 'checkbox',
'label' => __( 'Schedule Form', 'gravityforms' ),
'tooltip' => gform_tooltip( 'form_schedule_form', '', true ),
'choices' => array(
array(
'name' => 'scheduleForm',
'label' => __( 'Schedule Form', 'gravityforms' ),
),
),
'fields' => array(
array(
'name' => 'scheduleStart',
'type' => 'date_time',
'label' => esc_html__( 'Schedule Start Date/Time', 'gravityforms' ),
'dependency' => array(
'live' => true,
'fields' => array(
array(
'field' => 'scheduleForm',
),
),
),
),
array(
'name' => 'scheduleEnd',
'type' => 'date_time',
'label' => esc_html__( 'Schedule Form End Date/Time', 'gravityforms' ),
'dependency' => array(
'live' => true,
'fields' => array(
array(
'field' => 'scheduleForm',
),
),
),
),
array(
'name' => 'schedulePendingMessage',
'type' => 'textarea',
'label' => esc_html__( 'Form Pending Message', 'gravityforms' ),
'allow_html' => true,
'dependency' => array(
'live' => true,
'fields' => array(
array(
'field' => 'scheduleForm',
),
),
),
),
array(
'name' => 'scheduleMessage',
'type' => 'textarea',
'label' => esc_html__( 'Form Expired Message', 'gravityforms' ),
'allow_html' => true,
'dependency' => array(
'live' => true,
'fields' => array(
array(
'field' => 'scheduleForm',
),
),
),
),
),
),
array(
'name' => 'requireLogin',
'type' => 'checkbox',
'label' => __( 'Require user to be logged in', 'gravityforms' ),
'tooltip' => gform_tooltip( 'form_require_login', '', true ),
'choices' => array(
array(
'name' => 'requireLogin',
'label' => __( 'Require user to be logged in', 'gravityforms' ),
),
),
'fields' => array(
array(
'name' => 'requireLoginMessage',
'type' => 'textarea',
'label' => esc_html__( 'Require Login Message', 'gravityforms' ),
'tooltip' => gform_tooltip( 'form_require_login_message', '', true ),
'allow_html' => true,
'dependency' => array(
'live' => true,
'fields' => array(
array(
'field' => 'requireLogin',
),
),
),
),
),
),
),
),
'form_options' => array(
'title' => esc_html__( 'Form Options', 'gravityforms' ),
'fields' => array(
array(
'name' => 'enableHoneypot',
'type' => 'toggle',
'label' => esc_html__( 'Anti-spam honeypot', 'gravityforms' ),
'tooltip' => gform_tooltip( 'form_honeypot', '', true ),
),
array(
'name' => 'honeypotAction',
'type' => 'radio',
'default_value' => 'abort',
'horizontal' => true,
'label' => esc_html__( 'If the honeypot flags a submission as spam:', 'gravityforms' ),
'dependency' => array(
'live' => true,
'fields' => array(
array(
'field' => 'enableHoneypot',
),
),
),
'choices' => array(
array(
'label' => esc_html__( 'Do not create an entry', 'gravityforms' ),
'value' => 'abort',
),
array(
'label' => esc_html__( 'Create an entry and mark it as spam', 'gravityforms' ),
'value' => 'spam',
),
),
),
array(
'name' => 'enableAnimation',
'type' => 'toggle',
'label' => __( 'Animated transitions', 'gravityforms' ),
'tooltip' => gform_tooltip( 'form_animation', '', true ),
),
),
),
);
if ( self::show_legacy_markup_setting() ) {
$fields['form_options']['fields'][] = array(
'name' => 'markupVersion',
'type' => 'toggle',
'label' => __( 'Enable legacy markup', 'gravityforms' ),
'description' => self::legacy_markup_warning(),
'default_value' => rgar( $form, 'markupVersion' ) ? $form['markupVersion'] : 1,
'tooltip' => gform_tooltip( 'form_legacy_markup', '', true ),
);
}
/**
* Filters the form settings before they are displayed.
*
* @deprecated
* @remove-in 3.0
* @since 1.7
*
* @param array $form_settings The form settings.
* @param array $form The Form Object.
*/
if ( has_filter( 'gform_form_settings' ) ) {
trigger_error( 'gform_form_settings is deprecated and will be removed in version 3.0.', E_USER_DEPRECATED );
}
$legacy_settings = apply_filters( 'gform_form_settings', array(), $form );
// If legacy settings exist, add to fields.
if ( ! empty( $legacy_settings ) ) {
// Add section.
$fields['legacy_settings'] = array(
'title' => esc_html__( 'Legacy Settings', 'gravityforms' ),
'fields' => array(
array(
'name' => 'legacy',
'type' => 'html',
'html' => function() {
$form_id = rgget( 'id' );
$form = GFFormsModel::get_form_meta( $form_id );
$legacy_settings = apply_filters( 'gform_form_settings', array(), $form );
$html = '<table class="gforms_form_settings" cellspacing="0" cellpadding="0" width="100%">';
foreach ( $legacy_settings as $title => $legacy_fields ) {
$html .= sprintf( '<tr><td colspan="2"><h4 class="gf_settings_subgroup_title">%s</h4></td>', esc_html( $title ) );
if ( is_array( $legacy_fields ) ) {
foreach ( $legacy_fields as $field ) {
$html .= $field;
}
}
}
$html .= '</table>';
return $html;
},
),
),
);
}
/**
* Filters the form settings fields before they are displayed.
*
* @since 2.5
*
* @param array $fields Form settings fields.
* @param array $form Form Object.
*/
$fields = gf_apply_filters( array( 'gform_form_settings_fields', rgar( $form, 'id' ) ), $fields, $form );
return $fields;
}
/**
* Determine whether to show the legacy markup setting.
*
* @since 2.7.15
*
* @return bool
*/
public static function show_legacy_markup_setting() {
$show_legacy_setting = true;
if ( version_compare( get_option( 'rg_form_original_version', '1.0' ), '2.7.14.2', '>=' ) && ! self::legacy_is_in_use() ) {
$show_legacy_setting = false;
}
// if this is a new install, and if there are no forms with legacy markup enabled, do not show the legacy markup setting
return apply_filters( 'gform_show_legacy_markup_setting', $show_legacy_setting );
}
/**
* Check whether any forms on this site use legacy markup.
*
* @since 2.7.15
*
* @return bool
*/
public static function legacy_is_in_use() {
$legacy_is_in_use = GFCache::get( 'legacy_is_in_use', $found_in_cache );
if ( ! $found_in_cache ) {
$legacy_is_in_use = GFFormsModel::has_legacy_markup();
GFCache::set( 'legacy_is_in_use', $legacy_is_in_use, true, DAY_IN_SECONDS );
}
return $legacy_is_in_use;
}
/**
* Get the warning for the legacy markup field.
*
* @since 2.7.15
*
* @return string
*/
public static function legacy_markup_warning() {
return '<div class="gform-alert" data-js="gform-alert" role="status">
<span
class="gform-alert__icon gform-icon gform-icon--campaign"
aria-hidden="true"
></span>
<div class="gform-alert__message-wrap">
<p class="gform-alert__message">' . esc_html__( 'Legacy markup is incompatible with many new features, including the Orbital Theme.', 'gravityforms' ) . '</p>
<p class="gform-alert__message">' . esc_html__( 'Legacy markup will be removed in Gravity Forms 3.1.0, and then all forms will use modern markup. We recommend using modern markup on all forms.', 'gravityforms' ) . '</p>
<a
class="gform-alert__cta gform-button gform-button--white gform-button--size-xs"
href="https://docs.gravityforms.com/about-legacy-markup"
target="_blank"
aria-label="' . esc_html__( 'Learn more about form legacy markup', 'gravityforms' ) . '"
>'
. esc_html__( 'Learn More', 'gravityforms' ) .
'</a>
</div>
</div>';
}
// # SETTINGS RENDERER ---------------------------------------------------------------------------------------------
/**
* Initialize Plugin Settings fields renderer.
*
* @since 2.5
*/
public static function initialize_settings_renderer() {
require_once( GFCommon::get_base_path() . '/form_detail.php' );
$form_id = rgget( 'id' );
$form = GFCommon::gform_admin_pre_render( GFFormsModel::get_form_meta( $form_id ) );
// Initialize new settings renderer.
$renderer = new Settings(
array(
'fields' => array_values( self::form_settings_fields( $form ) ),
'initial_values' => self::get_initial_values( $form ),
'save_callback' => function( $values ) use ( &$form, $form_id ) {
// Set form version.
$form['version'] = GFForms::$version;
// Save custom settings fields to the form object if they don't already exist there.
$form = self::save_changed_form_settings_fields( $form, $values );
// Form Basics
$form['title'] = rgar( $values, 'title' );
$form['description'] = rgar( $values, 'description' );
// Form Layout
$form['labelPlacement'] = GFCommon::whitelist( rgar( $values, 'labelPlacement' ), array( 'top_label', 'left_label', 'right_label' ) );
$form['descriptionPlacement'] = GFCommon::whitelist( rgar( $values, 'descriptionPlacement' ), array( 'below', 'above' ) );
$form['validationPlacement'] = GFCommon::whitelist( rgar( $values, 'validationPlacement' ), array( 'below', 'above' ) );
$form['subLabelPlacement'] = GFCommon::whitelist( rgar( $values, 'subLabelPlacement' ), array( 'below', 'above' ) );
$form['validationSummary'] = rgar( $values, 'validationSummary', false );
$form['requiredIndicator'] = GFCommon::whitelist( rgar( $values, 'requiredIndicator' ), array( 'text', 'asterisk', 'custom' ) );
$form['customRequiredIndicator'] = rgar( $values, 'customRequiredIndicator' );
$form['cssClass'] = rgar( $values, 'cssClass' );
// Save and Continue
$form['save']['enabled'] = (bool) rgar( $values, 'saveEnabled' );
$form['save']['button']['type'] = 'link';
$form['save']['button']['text'] = rgar( $values, 'saveButtonText' );
// Limit Entries
$form['limitEntries'] = (bool) rgar( $values, 'limitEntries' );
$form['limitEntriesCount'] = absint( rgar( $values, 'limitEntriesCount' ) );
$form['limitEntriesPeriod'] = rgar( $values, 'limitEntriesPeriod' ) ? GFCommon::whitelist( $values['limitEntriesPeriod'], array( '', 'day', 'week', 'month', 'year' ) ) : '';
$form['limitEntriesMessage'] = rgar( $values, 'limitEntriesMessage' );
// Require Login
$form['requireLogin'] = (bool) rgar( $values, 'requireLogin' );
$form['requireLoginMessage'] = rgar( $values, 'requireLoginMessage' );
// Scheduling
$form['scheduleForm'] = rgar( $values, 'scheduleForm' );
$form['scheduleStart'] = rgars( $values, 'scheduleStart/date' );
$form['scheduleStartHour'] = rgars( $values, 'scheduleStart/hour' );
$form['scheduleStartMinute'] = rgars( $values, 'scheduleStart/minute' );
$form['scheduleStartAmpm'] = rgars( $values, 'scheduleStart/ampm' );
$form['scheduleEnd'] = rgars( $values, 'scheduleEnd/date' );
$form['scheduleEndHour'] = rgars( $values, 'scheduleEnd/hour' );
$form['scheduleEndMinute'] = rgars( $values, 'scheduleEnd/minute' );
$form['scheduleEndAmpm'] = rgars( $values, 'scheduleEnd/ampm' );
$form['schedulePendingMessage'] = rgar( $values, 'schedulePendingMessage' );
$form['scheduleMessage'] = rgar( $values, 'scheduleMessage' );
// Form Options
$form['enableHoneypot'] = (bool) rgar( $values, 'enableHoneypot' );
$form['honeypotAction'] = GFCommon::whitelist( rgar( $values, 'honeypotAction' ), array( 'abort', 'spam' ) );
$form['enableAnimation'] = (bool) rgar( $values, 'enableAnimation' );
$form['markupVersion'] = rgar( $values, 'markupVersion' ) ? 1 : 2;
// Enable/Disable Save & Continue.
if ( $form['save']['enabled'] ) {
$form = GFFormSettings::activate_save( $form );
} else {
$form = GFFormSettings::deactivate_save( $form );
}
/**
* Filters the updated form settings before being saved.
*
* @since 1.7
*
* @param array $form The form settings.
*/
$form = apply_filters( 'gform_pre_form_settings_save', $form );
// Save form.
GFFormDetail::save_form_info( $form_id, addslashes( json_encode( $form ) ) );
},
'before_fields' => function() use ( &$form ) {
?>
<script type="text/javascript">
<?php GFCommon::gf_global(); ?>
var form = <?php echo json_encode( $form ); ?>;
var fieldSettings = [];
jQuery( document ).ready( function() {
ToggleConditionalLogic( true, 'form_button' );
jQuery( document ).trigger( 'gform_load_form_settings', [ form ] );
} );
function SetButtonConditionalLogic(isChecked) {
form.button.conditionalLogic = isChecked ? new ConditionalLogic() : null;
}
<?php GFFormSettings::output_field_scripts() ?>
</script>
<?php
}
)
);
self::set_settings_renderer( $renderer );
// Process save callback.
if ( self::get_settings_renderer()->is_save_postback() ) {
self::get_settings_renderer()->process_postback();
}
}
/**
* Gets the current or default values of settings fields.
*
* Loop through all of the current settings and add in default values to pre-populate the settings fields.
*
* @since 2.5
*
* @param $form
*
* @return array
*/
private static function get_initial_values( $form ) {
$initial_values = array();
if ( empty( $form ) ) {
return $initial_values;
}
// Get all of the current values.
foreach ( $form as $key => $value ) {
if ( is_array( $value ) ) {
foreach ( $value as $sub_key => $sub_value ) {
if ( is_array( $sub_value ) ) {
foreach ( $sub_value as $third_key => $third_value ) {
$initial_values[ $key . ucfirst( $sub_key ) . ucfirst( $third_key ) ] = $third_value;
}
} else {
$initial_values[ $key . ucfirst( $sub_key ) ] = $sub_value;
}
}
} else {
$initial_values[ $key ] = $value;
}
}
// Start and end times are formatted differently than other fields.
$initial_values['scheduleStart'] = array(
'date' => rgar( $form, 'scheduleStart' ),
'hour' => rgar( $form, 'scheduleStartHour' ),
'minute' => rgar( $form, 'scheduleStartMinute' ),
'ampm' => rgar( $form, 'scheduleStartAmpm' ),
);
$initial_values['scheduleEnd'] = array(
'date' => rgar( $form, 'scheduleEnd' ),
'hour' => rgar( $form, 'scheduleEndHour' ),
'minute' => rgar( $form, 'scheduleEndMinute' ),
'ampm' => rgar( $form, 'scheduleEndAmpm' ),
);
// Conditional logic fields need different keys.
$initial_values['form_button_conditional_logic'] = isset( $form['button']['conditionalLogic'] ) && ! empty( $form['button']['conditionalLogic'] );
$initial_values['form_button_conditional_logic_object'] = rgars( $form, 'button/conditionalLogic' );
/**
* Filter the initial values that will be populated into the form settings.
*
* @since 2.5
*
* @param array $initial_values An associative array of setting names and their initial values.
* @param array $form The current form.
*/
return apply_filters( 'gform_form_settings_initial_values', $initial_values, $form );
}
/**
* Gets the current instance of Settings handling settings rendering.
*
* @since 2.5
*
* @return false|Gravity_Forms\Gravity_Forms\Settings\Settings
*/
private static function get_settings_renderer() {
return self::$_settings_renderer;
}
/**
* Sets the current instance of Settings handling settings rendering.
*
* @since 2.5
*
* @param Gravity_Forms\Gravity_Forms\Settings\Settings $renderer Settings renderer.
*
* @return bool|WP_Error
*/
private static function set_settings_renderer( $renderer ) {
// Ensure renderer is an instance of Settings
if ( ! is_a( $renderer, 'Gravity_Forms\Gravity_Forms\Settings\Settings' ) ) {
return new WP_Error( 'Renderer must be an instance of Gravity_Forms\Gravity_Forms\Settings\Settings.' );
}
self::$_settings_renderer = $renderer;
return true;
}
// # NOTIFICATIONS -------------------------------------------------------------------------------------------------
/**
* Runs the notification page.
*
* @since Unknown
* @access public
*
* @used-by GFFormSettings::form_settings_page()
* @uses GFNotification::notification_page()
*
* @return void
*/
public static function notification_page() {
require_once( 'notification.php' );
// Page header loaded in below function because admin messages were not yet available to the header to display.
GFNotification::notification_page();
}
/**
* Renders the Personal Data page.
*
* @since 2.4
*/
public static function personal_data_page() {
self::page_header( __( 'Personal Data', 'gravityforms' ) );
require_once( 'includes/class-personal-data.php' );
$form_id = absint( rgget( 'id' ) );
GF_Personal_Data::form_settings( $form_id );
self::page_footer();
}
/**
* Displays the form settings page header.
*
* @since Unknown
* @access public
*
* @used-by GFFormSettings::confirmations_edit_page()
* @used-by GFFormSettings::confirmations_list_page()
* @used-by GFFormSettings::form_settings_ui()
* @used-by GFNotification::notification_edit_page()
* @used-by GFNotification::notification_list_page()
* @used-by GFAddOn::form_settings_page()
* @uses SCRIPT_DEBUG
* @uses GFFormsModel::get_form_meta()
* @uses GFFormSettings::get_tabs()
* @uses GFCommon::form_page_title()
* @uses GFCommon::display_dismissible_message()
* @uses GFCommon::display_admin_message()
* @uses GFForms::top_toolbar()
* @uses GFCommon::get_browser_class()
*
* @param string $title The title to display as the page header. Defaults to empty string.
*
* @return void
*/
public static function page_header( $title = '' ) {
// Print admin styles.
wp_print_styles( array( 'jquery-ui-styles', 'gform_admin', 'gform_settings', 'wp-pointer' ) );