C:\xampp\htdocs\landing\wp-content\plugins\wpforms-lite\includes\fields\class-base.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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
<?php
/**
 * Base field template.
 *
 * @since 1.0.0
 */
abstract class WPForms_Field {

    
/**
     * Full name of the field type, eg "Paragraph Text".
     *
     * @since 1.0.0
     *
     * @var string
     */
    
public $name;

    
/**
     * Type of the field, eg "textarea".
     *
     * @since 1.0.0
     *
     * @var string
     */
    
public $type;

    
/**
     * Font Awesome Icon used for the editor button, eg "fa-list".
     *
     * @since 1.0.0
     *
     * @var mixed
     */
    
public $icon false;

    
/**
     * Priority order the field button should show inside the "Add Fields" tab.
     *
     * @since 1.0.0
     *
     * @var int
     */
    
public $order 1;

    
/**
     * Field group the field belongs to.
     *
     * @since 1.0.0
     *
     * @var string
     */
    
public $group 'standard';

    
/**
     * Placeholder to hold default value(s) for some field types.
     *
     * @since 1.0.0
     *
     * @var mixed
     */
    
public $defaults;

    
/**
     * Current form ID in the admin builder.
     *
     * @since 1.1.1
     *
     * @var int|bool
     */
    
public $form_id;

    
/**
     * Current field ID.
     *
     * @since 1.5.6
     *
     * @var int
     */
    
public $field_id;

    
/**
     * Current form data.
     *
     * @since 1.1.1
     *
     * @var array
     */
    
public $form_data;

    
/**
     * Current field data.
     *
     * @since 1.5.6
     *
     * @var array
     */
    
public $field_data;

    
/**
     * Primary class constructor.
     *
     * @since 1.0.0
     *
     * @param bool $init Pass false to allow to shortcut the whole initialization, if needed.
     */
    
public function __construct$init true ) {

        if ( ! 
$init ) {
            return;
        }

        
// The form ID is to be accessed in the builder.
        
$this->form_id = isset( $_GET['form_id'] ) ? (int) $_GET['form_id'] : false// phpcs:ignore WordPress.Security.NonceVerification

        // Bootstrap.
        
$this->init();

        
// Temporary solution to get an object of the field class.
        
add_filter(
            
"wpforms_fields_get_field_object_{$this->type}",
            function () {

                return 
$this;
            }
        );

        
// Add fields tab.
        
add_filter'wpforms_builder_fields_buttons', array( $this'field_button' ), 15 );

        
// Field options tab.
        
add_action"wpforms_builder_fields_options_{$this->type}", array( $this'field_options' ), 10 );

        
// Preview fields.
        
add_action"wpforms_builder_fields_previews_{$this->type}", array( $this'field_preview' ), 10 );

        
// AJAX Add new field.
        
add_action"wp_ajax_wpforms_new_field_{$this->type}", array( $this'field_new' ) );

        
// Display field input elements on front-end.
        
add_action"wpforms_display_field_{$this->type}", array( $this'field_display' ), 10);

        
// Validation on submit.
        
add_action"wpforms_process_validate_{$this->type}", array( $this'validate' ), 10);

        
// Format.
        
add_action"wpforms_process_format_{$this->type}", array( $this'format' ), 10);

        
// Prefill.
        
add_filter'wpforms_field_properties', array( $this'field_prefill_value_property' ), 10);

        
// Change the choice's value while saving entries.
        
add_filter'wpforms_process_before_form_data', [ $this'field_fill_empty_choices' ] );

        
// Change field name for ajax error.
        
add_filter'wpforms_process_ajax_error_field_name', [ $this'ajax_error_field_name' ], 10);
    }

    
/**
     * All systems go. Used by subclasses. Required.
     *
     * @since 1.0.0
     * @since 1.5.0 Converted to abstract method, as it's required for all fields.
     */
    
abstract public function init();

    
/**
     * Prefill field value with either fallback or dynamic data.
     * This needs to be public (although internal) to be used in WordPress hooks.
     *
     * @since 1.5.0
     *
     * @param array $properties Field properties.
     * @param array $field      Current field specific data.
     * @param array $form_data  Prepared form data/settings.
     *
     * @return array Modified field properties.
     */
    
public function field_prefill_value_property$properties$field$form_data ) {

        
// Process only for current field.
        
if ( $this->type !== $field['type'] ) {
            return 
$properties;
        }

        
// Set the form data, so we can reuse it later, even on front-end.
        
$this->form_data $form_data;

        
// Dynamic data.
        
if ( ! empty( $this->form_data['settings']['dynamic_population'] ) ) {
            
$properties $this->field_prefill_value_property_dynamic$properties$field );
        }

        
// Fallback data, rewrites dynamic because user-submitted data is more important.
        
$properties $this->field_prefill_value_property_fallback$properties$field );

        return 
$properties;
    }

    
/**
     * As we are processing user submitted data - ignore all admin-defined defaults.
     * Preprocess choices-related fields only.
     *
     * @since 1.5.0
     *
     * @param array $field      Field data and settings.
     * @param array $properties Properties we are modifying.
     */
    
public function field_prefill_remove_choices_defaults$field, &$properties ) {

        
// Skip this step on admin page.
        
if ( is_admin() && ! wpforms_is_admin_page'entries''edit' ) ) {
            return;
        }
        if (
            ! empty( 
$field['dynamic_choices'] ) ||
            ! empty( 
$field['choices'] )
        ) {
            
array_walk_recursive(
                
$properties['inputs'],
                function ( &
$value$key ) {

                    if ( 
'default' === $key ) {
                        
$value false;
                    }
                    if ( 
'wpforms-selected' === $value ) {
                        
$value '';
                    }
                }
            );
        }
    }

    
/**
     * Whether current field can be populated dynamically.
     *
     * @since 1.5.0
     *
     * @param array $properties Field properties.
     * @param array $field      Current field specific data.
     *
     * @return bool
     */
    
public function is_dynamic_population_allowed$properties$field ) {

        
$allowed true;

        
// Allow population on front-end only.
        
if ( is_admin() ) {
            
$allowed false;
        }

        
// For dynamic population we require $_GET.
        
if ( empty( $_GET ) ) { // phpcs:ignore
            
$allowed false;
        }

        return 
apply_filters'wpforms_field_is_dynamic_population_allowed'$allowed$properties$field );
    }

    
/**
     * Prefill the field value with a dynamic value, that we get from $_GET.
     * The pattern is: wpf4_12_primary, where:
     *      4 - form_id,
     *      12 - field_id,
     *      first - input key.
     * As 'primary' is our default input key, "wpf4_12_primary" and "wpf4_12" are the same.
     *
     * @since 1.5.0
     *
     * @param array $properties Field properties.
     * @param array $field      Current field specific data.
     *
     * @return array Modified field properties.
     */
    
protected function field_prefill_value_property_dynamic$properties$field ) {

        if ( ! 
$this->is_dynamic_population_allowed$properties$field ) ) {
            return 
$properties;
        }

        
// Iterate over each GET key, parse, and scrap data from there.
        
foreach ( $_GET as $key => $raw_value ) { // phpcs:ignore
            
preg_match'/wpf(\d+)_(\d+)(.*)/i'$key$matches );

            if ( empty( 
$matches ) || ! is_array$matches ) ) {
                continue;
            }

            
// Required.
            
$form_id  absint$matches[1] );
            
$field_id absint$matches[2] );
            
$input    'primary';

            
// Optional.
            
if ( ! empty( $matches[3] ) ) {
                
$input sanitize_keytrim$matches[3], '_' ) );
            }

            
// Both form and field IDs should be the same as current form/field.
            
if (
                (int) 
$this->form_data['id'] !== $form_id ||
                (int) 
$field['id'] !== $field_id
            
) {
                
// Go to the next GET param.
                
continue;
            }

            if ( ! empty( 
$raw_value ) ) {
                
$this->field_prefill_remove_choices_defaults$field$properties );
            }

            
/*
             * Some fields (like checkboxes) support multiple selection.
             * We do not support nested values, so omit them.
             * Example: ?wpf771_19_wpforms[fields][19][address1]=test
             * In this case:
             *      $input = wpforms
             *      $raw_value = [fields=>[]]
             *      $single_value = [19=>[]]
             * There is no reliable way to clean those things out.
             * So we will ignore the value altogether if it's an array.
             * We support only single value numeric arrays, like these:
             *      ?wpf771_19[]=test1&wpf771_19[]=test2
             *      ?wpf771_19_value[]=test1&wpf771_19_value[]=test2
             *      ?wpf771_41_r3_c2[]=1&wpf771_41_r1_c4[]=1
             */
            
if ( is_array$raw_value ) ) {
                foreach ( 
$raw_value as $single_value ) {
                    
$properties $this->get_field_populated_single_property_value$single_value$input$properties$field );
                }
            } else {
                
$properties $this->get_field_populated_single_property_value$raw_value$input$properties$field );
            }
        }

        return 
$properties;
    }

    
/**
     * Public version of get_field_populated_single_property_value() to use by external classes.
     *
     * @since 1.6.0.1
     *
     * @param string $raw_value  Value from a GET param, always a string.
     * @param string $input      Represent a subfield inside the field. May be empty.
     * @param array  $properties Field properties.
     * @param array  $field      Current field specific data.
     *
     * @return array Modified field properties.
     */
    
public function get_field_populated_single_property_value_public$raw_value$input$properties$field ) {

        return 
$this->get_field_populated_single_property_value$raw_value$input$properties$field );
    }

    
/**
     * Get the value, that is used to prefill via dynamic or fallback population.
     * Based on field data and current properties.
     *
     * @since 1.5.0
     *
     * @param string $raw_value  Value from a GET param, always a string.
     * @param string $input      Represent a subfield inside the field. May be empty.
     * @param array  $properties Field properties.
     * @param array  $field      Current field specific data.
     *
     * @return array Modified field properties.
     */
    
protected function get_field_populated_single_property_value$raw_value$input$properties$field ) {

        if ( ! 
is_string$raw_value ) ) {
            return 
$properties;
        }

        
$get_value stripslashessanitize_text_field$raw_value ) );

        
// For fields that have dynamic choices we need to add extra logic.
        
if ( ! empty( $field['dynamic_choices'] ) ) {

            
$properties $this->get_field_populated_single_property_value_dynamic_choices$get_value$properties );

        } elseif ( ! empty( 
$field['choices'] ) && is_array$field['choices'] ) ) {

            
$properties $this->get_field_populated_single_property_value_normal_choices$get_value$properties$field );

        } else {
            
/*
             * For other types of fields we need to check that
             * the key is registered for the defined field in inputs array.
             */
            
if (
                ! empty( 
$input ) &&
                isset( 
$properties['inputs'][ $input ] )
            ) {
                
$properties['inputs'][ $input ]['attr']['value'] = $get_value;
            }
        }

        return 
$properties;
    }

    
/**
     * Get the value, that is used to prefill via dynamic or fallback population.
     * Based on field data and current properties.
     * Dynamic choices section.
     *
     * @since 1.6.0
     *
     * @param string $get_value  Value from a GET param, always a string, sanitized, stripped slashes.
     * @param array  $properties Field properties.
     *
     * @return array Modified field properties.
     */
    
protected function get_field_populated_single_property_value_dynamic_choices$get_value$properties ) {

        
$default_key null;

        foreach ( 
$properties['inputs'] as $input_key => $input_arr ) {
            
// Dynamic choices support only integers in its values.
            
if ( absint$get_value ) === $input_arr['attr']['value'] ) {
                
$default_key $input_key;
                
// Stop iterating over choices.
                
break;
            }
        }

        
// Redefine default choice only if dynamic value has changed anything.
        
if ( null !== $default_key ) {
            foreach ( 
$properties['inputs'] as $input_key => $choice_arr ) {
                if ( 
$input_key === $default_key ) {
                    
$properties['inputs'][ $input_key ]['default']              = true;
                    
$properties['inputs'][ $input_key ]['container']['class'][] = 'wpforms-selected';
                    
// Stop iterating over choices.
                    
break;
                }
            }
        }

        return 
$properties;
    }

    
/**
     * Fill choices without labels.
     *
     * @since 1.6.2
     *
     * @param array $form_data Form data.
     *
     * @return array
     */
    
public function field_fill_empty_choices$form_data ) {

        if ( empty( 
$form_data['fields'] ) ) {
            return 
$form_data;
        }

        
// Set value for choices with the image only. Conditional logic doesn't work without value.
        
foreach ( $form_data['fields'] as $field_key => $field ) {
            
// Payment fields have their labels set up upfront.
            
if ( empty( $field['choices'] ) || ! in_array$field['type'], [ 'radio''checkbox' ], true ) ) {
                continue;
            }

            foreach ( 
$field['choices'] as $choice_id => $choice ) {
                if ( ( isset( 
$choice['value'] ) && '' !== trim$choice['value'] ) ) || empty( $choice['image'] ) ) {
                    continue;
                }
                
/* translators: %d - choice number. */
                
$form_data['fields'][ $field_key ]['choices'][ $choice_id ]['value'] = sprintfesc_html__'Choice %d''wpforms-lite' ), (int) $choice_id );
            }
        }

        return 
$form_data;
    }

    
/**
     * Get the value, that is used to prefill via dynamic or fallback population.
     * Based on field data and current properties.
     * Normal choices section.
     *
     * @since 1.6.0
     *
     * @param string $get_value  Value from a GET param, always a string, sanitized.
     * @param array  $properties Field properties.
     * @param array  $field      Current field specific data.
     *
     * @return array Modified field properties.
     */
    
protected function get_field_populated_single_property_value_normal_choices$get_value$properties$field ) {

        
$default_key null;

        
// For fields that have normal choices we need to add extra logic.
        
foreach ( $field['choices'] as $choice_key => $choice_arr ) {
            
$choice_value_key = isset( $field['show_values'] ) ? 'value' 'label';
            if (
                (
                    isset( 
$choice_arr$choice_value_key ] ) &&
                    
strtouppersanitize_text_field$choice_arr$choice_value_key ] ) ) === strtoupper$get_value )
                ) ||
                (
                    empty( 
$choice_arr$choice_value_key ] ) &&
                    
/* translators: %d - choice number. */
                    
$get_value === sprintfesc_html__'Choice %d''wpforms-lite' ), (int) $choice_key )
                )
            ) {
                
$default_key $choice_key;
                
// Stop iterating over choices.
                
break;
            }
        }

        
// Redefine default choice only if population value has changed anything.
        
if ( null !== $default_key ) {
            foreach ( 
$field['choices'] as $choice_key => $choice_arr ) {
                if ( 
$choice_key === $default_key ) {
                    
$properties['inputs'][ $choice_key ]['default']              = true;
                    
$properties['inputs'][ $choice_key ]['container']['class'][] = 'wpforms-selected';
                    break;
                }
            }
        }

        return 
$properties;
    }

    
/**
     * Whether current field can be populated dynamically.
     *
     * @since 1.5.0
     *
     * @param array $properties Field properties.
     * @param array $field      Current field specific data.
     *
     * @return bool
     */
    
public function is_fallback_population_allowed$properties$field ) {

        
$allowed true;

        
// Allow population on front-end only.
        
if ( is_admin() ) {
            
$allowed false;
        }

        
/*
         * Commented out to allow partial fail for complex multi-inputs fields.
         * Example: name field with first/last format and being required, filled out only first.
         * On submit we will preserve those sub-inputs that are not empty and display an error for an empty.
         */
        // Do not populate if there are errors for that field.
        /*
        $errors = wpforms()->process->errors;
        if ( ! empty( $errors[ $this->form_data['id'] ][ $field['id'] ] ) ) {
            $allowed = false;
        }
        */

        // Require form id being the same for submitted and currently rendered form.
        
if (
            ! empty( 
$_POST['wpforms']['id'] ) && // phpcs:ignore
            
(int) $_POST['wpforms']['id'] !== (int) $this->form_data['id'// phpcs:ignore
        
) {
            
$allowed false;
        }

        
// Require $_POST of submitted field.
        
if ( empty( $_POST['wpforms']['fields'] ) ) { // phpcs:ignore
            
$allowed false;
        }

        
// Require field (processed and rendered) being the same.
        
if ( ! isset( $_POST['wpforms']['fields'][ $field['id'] ] ) ) { // phpcs:ignore
            
$allowed false;
        }

        return 
apply_filters'wpforms_field_is_fallback_population_allowed'$allowed$properties$field );
    }

    
/**
     * Prefill the field value with a fallback value from form submission (in case of JS validation failed), that we get from $_POST.
     *
     * @since 1.5.0
     *
     * @param array $properties Field properties.
     * @param array $field      Current field specific data.
     *
     * @return array Modified field properties.
     */
    
protected function field_prefill_value_property_fallback$properties$field ) {

        if ( ! 
$this->is_fallback_population_allowed$properties$field ) ) {
            return 
$properties;
        }

        if ( empty( 
$_POST['wpforms']['fields'] ) || ! is_array$_POST['wpforms']['fields'] ) ) { // phpcs:ignore
            
return $properties;
        }

        
// We got user submitted raw data (not processed, will be done later).
        
$raw_value $_POST['wpforms']['fields'][ $field['id'] ]; // phpcs:ignore
        
$input     'primary';

        if ( ! empty( 
$raw_value ) ) {
            
$this->field_prefill_remove_choices_defaults$field$properties );
        }

        
/*
         * For this particular field this value may be either array or a string.
         * In array - this is a complex field, like address.
         * The key in array will be a sub-input (address1, state), and its appropriate value.
         */
        
if ( is_array$raw_value ) ) {
            foreach ( 
$raw_value as $input => $single_value ) {
                
$properties $this->get_field_populated_single_property_value$single_valuesanitize_key$input ), $properties$field );
            }
        } else {
            
$properties $this->get_field_populated_single_property_value$raw_valuesanitize_key$input ), $properties$field );
        }

        return 
$properties;
    }

    
/**
     * Create the button for the 'Add Fields' tab, inside the form editor.
     *
     * @since 1.0.0
     *
     * @param array $fields List of form fields with their data.
     *
     * @return array
     */
    
public function field_button$fields ) {

        
// Add field information to fields array.
        
$fields$this->group ]['fields'][] = array(
            
'order' => $this->order,
            
'name'  => $this->name,
            
'type'  => $this->type,
            
'icon'  => $this->icon,
        );

        
// Wipe hands clean.
        
return $fields;
    }

    
/**
     * Create the field options panel. Used by subclasses.
     *
     * @since 1.0.0
     * @since 1.5.0 Converted to abstract method, as it's required for all fields.
     *
     * @param array $field Field data and settings.
     */
    
abstract public function field_options$field );

    
/**
     * Create the field preview. Used by subclasses.
     *
     * @since 1.0.0
     * @since 1.5.0 Converted to abstract method, as it's required for all fields.
     *
     * @param array $field Field data and settings.
     */
    
abstract public function field_preview$field );

    
/**
     * Helper function to create field option elements.
     *
     * Field option elements are pieces that help create a field option.
     * They are used to quickly build field options.
     *
     * @since 1.0.0
     *
     * @param string $option Field option to render.
     * @param array  $field  Field data and settings.
     * @param array  $args   Field preview arguments.
     * @param bool   $echo   Print or return the value. Print by default.
     *
     * @return mixed echo or return string
     */
    
public function field_element$option$field$args = array(), $echo true ) {

        
$id     = (int) $field['id'];
        
$class  = ! empty( $args['class'] ) ? wpforms_sanitize_classes( (array) $args['class'], true ) : '';
        
$slug   = ! empty( $args['slug'] ) ? sanitize_title$args['slug'] ) : '';
        
$attrs  '';
        
$output '';

        if ( ! empty( 
$args['data'] ) ) {
            foreach ( 
$args['data'] as $arg_key => $val ) {
                if ( 
is_array$val ) ) {
                    
$val wp_json_encode$val );
                }
                
$attrs .= ' data-' $arg_key '=\'' $val '\'';
            }
        }
        if ( ! empty( 
$args['attrs'] ) ) {
            foreach ( 
$args['attrs'] as $arg_key => $val ) {
                if ( 
is_array$val ) ) {
                    
$val wp_json_encode$val );
                }
                
$attrs .= $arg_key '=\'' $val '\'';
            }
        }

        switch ( 
$option ) {

            
// Row.
            
case 'row':
                
$output sprintf(
                    
'<div class="wpforms-field-option-row wpforms-field-option-row-%s %s" id="wpforms-field-option-row-%d-%s" data-field-id="%d" %s>%s</div>',
                    
$slug,
                    
$class,
                    
$id,
                    
$slug,
                    
$id,
                    
$attrs,
                    
$args['content']
                );
                break;

            
// Label.
            
case 'label':
                
$class  = ! empty( $class ) ? ' class="' $class '"' '';
                
$output sprintf'<label for="wpforms-field-option-%d-%s"%s>%s'$id$slug$classesc_html$args['value'] ) );
                if ( isset( 
$args['tooltip'] ) && ! empty( $args['tooltip'] ) ) {
                    
$output .= ' ' sprintf'<i class="fa fa-question-circle wpforms-help-tooltip" title="%s"></i>'esc_attr$args['tooltip'] ) );
                }
                if ( isset( 
$args['after_tooltip'] ) && ! empty( $args['after_tooltip'] ) ) {
                    
$output .= $args['after_tooltip'];
                }
                
$output .= '</label>';
                break;

            
// Text input.
            
case 'text':
                
$type        = ! empty( $args['type'] ) ? esc_attr$args['type'] ) : 'text';
                
$placeholder = ! empty( $args['placeholder'] ) ? esc_attr$args['placeholder'] ) : '';
                
$before      = ! empty( $args['before'] ) ? '<span class="before-input">' esc_html$args['before'] ) . '</span>' '';
                if ( ! empty( 
$before ) ) {
                    
$class .= ' has-before';
                }
                
$output sprintf'%s<input type="%s" class="%s" id="wpforms-field-option-%d-%s" name="fields[%d][%s]" value="%s" placeholder="%s" %s>'$before$type$class$id$slug$id$slugesc_attr$args['value'] ), $placeholder$attrs );
                break;

            
// Textarea.
            
case 'textarea':
                
$rows   = ! empty( $args['rows'] ) ? (int) $args['rows'] : '3';
                
$output sprintf'<textarea class="%s" id="wpforms-field-option-%d-%s" name="fields[%d][%s]" rows="%d" %s>%s</textarea>'$class$id$slug$id$slug$rows$attrs$args['value'] );
                break;

            
// Checkbox.
            
case 'checkbox':
                
$checked checked'1'$args['value'], false );
                
$output  sprintf'<input type="checkbox" class="%s" id="wpforms-field-option-%d-%s" name="fields[%d][%s]" value="1" %s %s>'$class$id$slug$id$slug$checked$attrs );
                
$output .= empty( $args['nodesc'] ) ? sprintf'<label for="wpforms-field-option-%d-%s" class="inline">%s'$id$slug$args['desc'] ) : '';
                if ( isset( 
$args['tooltip'] ) && ! empty( $args['tooltip'] ) ) {
                    
$output .= ' ' sprintf'<i class="fa fa-question-circle wpforms-help-tooltip" title="%s"></i>'esc_attr$args['tooltip'] ) );
                }
                
$output .= empty( $args['nodesc'] ) ? '</label>' '';
                break;

            
// Toggle.
            
case 'toggle':
                
$checked checked'1'$args['value'], false );
                
$icon    $args['value'] ? 'fa-toggle-on' 'fa-toggle-off';
                
$cls     $args['value'] ? 'wpforms-on' 'wpforms-off';
                
$status  $args['value'] ? esc_html__'On''wpforms-lite' ) : esc_html__'Off''wpforms-lite' );
                
$output  sprintf'<span class="wpforms-toggle-icon %s"><i class="fa %s" aria-hidden="true"></i> <span class="wpforms-toggle-icon-label">%s</span>'$cls$icon$status );
                
$output .= sprintf'<input type="checkbox" class="%s" id="wpforms-field-option-%d-%s" name="fields[%d][%s]" value="1" %s %s></span>'$class$id$slug$id$slug$checked$attrs );
                break;

            
// Select.
            
case 'select':
                
$options $args['options'];
                
$value   = isset( $args['value'] ) ? $args['value'] : '';
                
$output  sprintf'<select class="%s" id="wpforms-field-option-%d-%s" name="fields[%d][%s]" %s>'$class$id$slug$id$slug$attrs );
                foreach ( 
$options as $arg_key => $arg_option ) {
                    
$output .= sprintf'<option value="%s" %s>%s</option>'esc_attr$arg_key ), selected$arg_key$valuefalse ), $arg_option );
                }
                
$output .= '</select>';
                break;
        }

        if ( ! 
$echo ) {
            return 
$output;
        }

        echo 
$output// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
    
}

    
/**
     * Helper function to create common field options that are used frequently.
     *
     * @since 1.0.0
     *
     * @param string $option Field option to render.
     * @param array  $field  Field data and settings.
     * @param array  $args   Field preview arguments.
     * @param bool   $echo   Print or return the value. Print by default.
     *
     * @return mixed echo or return string
     */
    
public function field_option$option$field$args = array(), $echo true ) {

        switch ( 
$option ) {

            
/**
             * Basic Fields.
             */

            /*
             * Basic Options markup.
             */
            
case 'basic-options':
                
$markup = ! empty( $args['markup'] ) ? $args['markup'] : 'open';
                
$class  = ! empty( $args['class'] ) ? esc_html$args['class'] ) : '';
                if ( 
'open' === $markup ) {
                    
$output  sprintf'<div class="wpforms-field-option-group wpforms-field-option-group-basic" id="wpforms-field-option-basic-%d">'$field['id'] );
                    
$output .= sprintf'<a href="#" class="wpforms-field-option-group-toggle">%s <span>(ID #%d)</span> <i class="fa fa-angle-down"></i></a>'$this->name$field['id'] );
                    
$output .= sprintf'<div class="wpforms-field-option-group-inner %s">'$class );
                } else {
                    
$output '</div></div>';
                }
                break;

            
/*
             * Field Label.
             */
            
case 'label':
                
$value   = ! empty( $field['label'] ) ? esc_attr$field['label'] ) : '';
                
$tooltip esc_html__'Enter text for the form field label. Field labels are recommended and can be hidden in the Advanced Settings.''wpforms-lite' );
                
$output  $this->field_element'label'$field, array( 'slug' => 'label''value' => esc_html__'Label''wpforms-lite' ), 'tooltip' => $tooltip ), false );
                
$output .= $this->field_element'text',  $field, array( 'slug' => 'label''value' => $value ), false );
                
$output  $this->field_element'row',   $field, array( 'slug' => 'label''content' => $output ), false );
                break;

            
/*
             * Field Description.
             */
            
case 'description':
                
$value   = ! empty( $field['description'] ) ? esc_attr$field['description'] ) : '';
                
$tooltip esc_html__'Enter text for the form field description.''wpforms-lite' );
                
$output  $this->field_element'label',    $field, array( 'slug' => 'description''value' => esc_html__'Description''wpforms-lite' ), 'tooltip' => $tooltip ), false );
                
$output .= $this->field_element'textarea'$field, array( 'slug' => 'description''value' => $value ), false );
                
$output  $this->field_element'row',      $field, array( 'slug' => 'description''content' => $output ), false );
                break;

            
/*
             * Field Required toggle.
             */
            
case 'required':
                
$default = ! empty( $args['default'] ) ? $args['default'] : '0';
                
$value   = isset( $field['required'] ) ? $field['required'] : $default;
                
$tooltip esc_html__'Check this option to mark the field required. A form will not submit unless all required fields are provided.''wpforms-lite' );
                
$output  $this->field_element'checkbox'$field, array( 'slug' => 'required''value' => $value'desc' => esc_html__'Required''wpforms-lite' ), 'tooltip' => $tooltip ), false );
                
$output  $this->field_element'row',      $field, array( 'slug' => 'required''content' => $output ), false );
                break;

            
/*
             * Field Meta (field type and ID).
             */
            
case 'meta':
                
$output  sprintf'<label>%s</label>''Type' );
                
$output .= sprintf'<p class="meta">%s <span class="id">(ID #%d)</span></p>'$this->name$field['id'] );
                
$output  $this->field_element'row'$field, array( 'slug' => 'meta''content' => $output ), false );
                break;

            
/*
             * Code Block.
             */
            
case 'code':
                
$value   = ! empty( $field['code'] ) ? esc_textarea$field['code'] ) : '';
                
$tooltip esc_html__'Enter code for the form field.''wpforms-lite' );
                
$output  $this->field_element'label',    $field, array( 'slug' => 'code''value' => esc_html__'Code''wpforms-lite' ), 'tooltip' => $tooltip ), false );
                
$output .= $this->field_element'textarea'$field, array( 'slug' => 'code''value' => $value ), false );
                
$output  $this->field_element'row',      $field, array( 'slug' => 'code''content' => $output ), false );
                break;

            
/*
             * Choices.
             */
            
case 'choices':
                
$values     = ! empty( $field['choices'] ) ? $field['choices'] : $this->defaults;
                
$label      = ! empty( $args['label'] ) ? esc_html$args['label'] ) : esc_html__'Choices''wpforms-lite' );
                
$class      = array();
                
$field_type $this->type;

                if ( ! empty( 
$field['multiple'] ) ) {
                    
$field_type 'checkbox';
                }

                if ( ! empty( 
$field['show_values'] ) ) {
                    
$class[] = 'show-values';
                }
                if ( ! empty( 
$field['dynamic_choices'] ) ) {
                    
$class[] = 'wpforms-hidden';
                }
                if ( ! empty( 
$field['choices_images'] ) ) {
                    
$class[] = 'show-images';
                }

                
// Field label.
                
$lbl $this->field_element(
                    
'label',
                    
$field,
                    array(
                        
'slug'          => 'choices',
                        
'value'         => $label,
                        
'tooltip'       => esc_html__'Add choices for the form field.''wpforms-lite' ),
                        
'after_tooltip' => '<a href="#" class="toggle-bulk-add-display"><i class="fa fa-download"></i> <span>' esc_html__'Bulk Add''wpforms-lite' ) . '</span></a>',
                    ),
                    
false
                
);

                
// Field contents.
                
$fld sprintf(
                    
'<ul data-next-id="%s" class="choices-list %s" data-field-id="%d" data-field-type="%s">',
                    
maxarray_keys$values ) ) + 1,
                    
wpforms_sanitize_classes$classtrue ),
                    
$field['id'],
                    
$this->type
                
);
                foreach ( 
$values as $key => $value ) {
                    
$default   = ! empty( $value['default'] ) ? $value['default'] : '';
                    
$base      sprintf'fields[%s][choices][%s]'$field['id'], $key );
                    
$image     = ! empty( $value['image'] ) ? $value['image'] : '';
                    
$image_btn '';

                    
$fld .= '<li data-key="' absint$key ) . '">';
                    
$fld .= sprintf(
                        
'<input type="%s" name="%s[default]" class="default" value="1" %s>',
                        
'checkbox' === $field_type 'checkbox' 'radio',
                        
$base,
                        
checked'1'$defaultfalse )
                    );
                    
$fld .= '<span class="move"><i class="fa fa-bars"></i></span>';
                    
$fld .= sprintf(
                        
'<input type="text" name="%s[label]" value="%s" class="label">',
                        
$base,
                        
esc_attr$value['label'] )
                    );
                    
$fld .= '<a class="add" href="#"><i class="fa fa-plus-circle"></i></a><a class="remove" href="#"><i class="fa fa-minus-circle"></i></a>';
                    
$fld .= sprintf(
                        
'<input type="text" name="%s[value]" value="%s" class="value">',
                        
$base,
                        
esc_attr( ! isset( $value['value'] ) ? '' $value['value'] )
                    );
                    
$fld .= '<div class="wpforms-image-upload">';
                    
$fld .= '<div class="preview">';
                    if ( ! empty( 
$image ) ) {
                        
$fld .= sprintf(
                            
'<a href="#" title="%s" class="wpforms-image-upload-remove"><img src="%s"></a>',
                            
esc_attr__'Remove Image''wpforms-lite' ),
                            
esc_url_raw$image )
                        );

                        
$image_btn ' style="display:none;"';
                    }
                    
$fld .= '</div>';
                    
$fld .= sprintf(
                        
'<button class="wpforms-btn wpforms-btn-md wpforms-btn-light-grey wpforms-btn-block wpforms-image-upload-add" data-after-upload="hide"%s>%s</button>',
                        
$image_btn,
                        
esc_html__'Upload Image''wpforms-lite' )
                    );
                    
$fld .= sprintf(
                        
'<input type="hidden" name="%s[image]" value="%s" class="source">',
                        
$base,
                        
esc_url_raw$image )
                    );
                    
$fld .= '</div>';
                    
$fld .= '</li>';
                }
                
$fld .= '</ul>';

                
// Field note: dynamic status.
                
$source  '';
                
$type    '';
                
$dynamic = ! empty( $field['dynamic_choices'] ) ? esc_html$field['dynamic_choices'] ) : '';

                if ( 
'post_type' === $dynamic && ! empty( $field'dynamic_' $dynamic ] ) ) {
                    
$type   esc_html__'post type''wpforms-lite' );
                    
$pt     get_post_type_object$field'dynamic_' $dynamic ] );
                    
$source '';
                    if ( 
null !== $pt ) {
                        
$source $pt->labels->name;
                    }
                } elseif ( 
'taxonomy' === $dynamic && ! empty( $field'dynamic_' $dynamic ] ) ) {
                    
$type   esc_html__'taxonomy''wpforms-lite' );
                    
$tax    get_taxonomy$field'dynamic_' $dynamic ] );
                    
$source '';
                    if ( 
false !== $tax ) {
                        
$source $tax->labels->name;
                    }
                }

                
$note sprintf(
                    
'<div class="wpforms-alert-warning wpforms-alert-small wpforms-alert %s">',
                    ! empty( 
$dynamic ) && ! empty( $field'dynamic_' $dynamic ] ) ? '' 'wpforms-hidden'
                
);

                
$note .= sprintf(
                    
/* translators: %1$s - source name; %2$s - type name. */
                    
esc_html__'Choices are dynamically populated from the %1$s %2$s.''wpforms-lite' ),
                    
'<span class="dynamic-name">' $source '</span>',
                    
'<span class="dynamic-type">' $type '</span>'
                
);
                
$note .= '</div>';

                
// Final field output.
                
$output $this->field_element(
                    
'row',
                    
$field,
                    array(
                        
'slug'    => 'choices',
                        
'content' => $lbl $fld $note,
                    ),
                    
false
                
);
                break;

            
/*
             * Choices for payments.
             */
            
case 'choices_payments':
                
$values     = ! empty( $field['choices'] ) ? $field['choices'] : $this->defaults;
                
$class      = array();
                
$input_type in_array$field['type'], array( 'payment-multiple''payment-select' ), true ) ? 'radio' 'checkbox';

                if ( ! empty( 
$field['choices_images'] ) ) {
                    
$class[] = 'show-images';
                }

                
// Field label.
                
$lbl $this->field_element(
                    
'label',
                    
$field,
                    array(
                        
'slug'    => 'choices',
                        
'value'   => esc_html__'Items''wpforms-lite' ),
                        
'tooltip' => esc_html__'Add choices for the form field.''wpforms-lite' ),
                    ),
                    
false
                
);

                
// Field contents.
                
$fld sprintf(
                    
'<ul data-next-id="%s" class="choices-list %s" data-field-id="%d" data-field-type="%s">',
                    
maxarray_keys$values ) ) + 1,
                    
wpforms_sanitize_classes$classtrue ),
                    
$field['id'],
                    
$this->type
                
);
                foreach ( 
$values as $key => $value ) {
                    
$default   = ! empty( $value['default'] ) ? $value['default'] : '';
                    
$base      sprintf'fields[%s][choices][%s]'$field['id'], $key );
                    
$image     = ! empty( $value['image'] ) ? $value['image'] : '';
                    
$image_btn '';

                    
$fld .= '<li data-key="' absint$key ) . '">';
                    
$fld .= sprintf(
                        
'<input type="%s" name="%s[default]" class="default" value="1" %s>',
                        
$input_type,
                        
$base,
                        
checked'1'$defaultfalse )
                    );
                    
$fld .= '<span class="move"><i class="fa fa-bars"></i></span>';
                    
$fld .= sprintf(
                        
'<input type="text" name="%s[label]" value="%s" class="label">',
                        
$base,
                        
esc_attr$value['label'] )
                    );
                    
$fld .= sprintf(
                        
'<input type="text" name="%s[value]" value="%s" class="value wpforms-money-input" placeholder="%s">',
                        
$base,
                        
esc_attr$value['value'] ),
                        
wpforms_format_amount)
                    );
                    
$fld .= '<a class="add" href="#"><i class="fa fa-plus-circle"></i></a><a class="remove" href="#"><i class="fa fa-minus-circle"></i></a>';
                    
$fld .= '<div class="wpforms-image-upload">';
                    
$fld .= '<div class="preview">';
                    if ( ! empty( 
$image ) ) {
                        
$fld .= sprintf(
                            
'<a href="#" title="%s" class="wpforms-image-upload-remove"><img src="%s"></a>',
                            
esc_attr__'Remove Image''wpforms-lite' ),
                            
esc_url_raw$image )
                        );

                        
$image_btn ' style="display:none;"';
                    }
                    
$fld .= '</div>';
                    
$fld .= sprintf(
                        
'<button class="wpforms-btn wpforms-btn-md wpforms-btn-light-grey wpforms-btn-block wpforms-image-upload-add" data-after-upload="hide"%s>%s</button>',
                        
$image_btn,
                        
esc_html__'Upload Image''wpforms-lite' )
                    );
                    
$fld .= sprintf(
                        
'<input type="hidden" name="%s[image]" value="%s" class="source">',
                        
$base,
                        
esc_url_raw$image )
                    );
                    
$fld .= '</div>';
                    
$fld .= '</li>';
                }
                
$fld .= '</ul>';

                
// Final field output.
                
$output $this->field_element(
                    
'row',
                    
$field,
                    array(
                        
'slug'    => 'choices',
                        
'content' => $lbl $fld,
                    ),
                    
false
                
);
                break;

            
/*
             * Choices Images.
             */
            
case 'choices_images':
                
// Field note: Image tips.
                
$note  sprintf(
                    
'<div class="wpforms-alert-warning wpforms-alert-small wpforms-alert %s">',
                    ! empty( 
$field['choices_images'] ) ? '' 'wpforms-hidden'
                
);
                
$note .= esc_html__'Images are not cropped or resized. For best results, they should be the same size and 250x250 pixels or smaller.''wpforms-lite' );
                
$note .= '</div>';

                
// Field contents.
                
$fld $this->field_element(
                    
'checkbox',
                    
$field,
                    array(
                        
'slug'    => 'choices_images',
                        
'value'   => isset( $field['choices_images'] ) ? '1' '0',
                        
'desc'    => esc_html__'Use image choices''wpforms-lite' ),
                        
'tooltip' => esc_html__'Check this option to enable using images with the choices.''wpforms-lite' ),
                    ),
                    
false
                
);

                
// Final field output.
                
$output $this->field_element(
                    
'row',
                    
$field,
                    array(
                        
'slug'    => 'choices_images',
                        
'class'   => ! empty( $field['dynamic_choices'] ) ? 'wpforms-hidden' '',
                        
'content' => $note $fld,
                    ),
                    
false
                
);
                break;

            
/*
             * Choices Images Style.
             */
            
case 'choices_images_style':
                
// Field label.
                
$lbl $this->field_element(
                    
'label',
                    
$field,
                    array(
                        
'slug'    => 'choices_images_style',
                        
'value'   => esc_html__'Image Choice Style''wpforms-lite' ),
                        
'tooltip' => esc_html__'Select the style for the image choices.''wpforms-lite' ),
                    ),
                    
false
                
);

                
// Field contents.
                
$fld $this->field_element(
                    
'select',
                    
$field,
                    array(
                        
'slug'    => 'choices_images_style',
                        
'value'   => ! empty( $field['choices_images_style'] ) ? esc_attr$field['choices_images_style'] ) : 'modern',
                        
'options' => array(
                            
'modern'  => esc_html__'Modern''wpforms-lite' ),
                            
'classic' => esc_html__'Classic''wpforms-lite' ),
                            
'none'    => esc_html__'None''wpforms-lite' ),
                        ),
                    ),
                    
false
                
);

                
// Final field output.
                
$output $this->field_element(
                    
'row',
                    
$field,
                    array(
                        
'slug'    => 'choices_images_style',
                        
'content' => $lbl $fld,
                        
'class'   => ! empty( $field['choices_images'] ) ? '' 'wpforms-hidden',
                    ),
                    
false
                
);
                break;

            
/**
             * Advanced Fields.
             */

            /*
             * Default value.
             */
            
case 'default_value':
                
$value   = ! empty( $field['default_value'] ) || ( isset( $field['default_value'] ) && '0' === (string) $field['default_value'] ) ? esc_attr$field['default_value'] ) : '';
                
$tooltip esc_html__'Enter text for the default form field value.''wpforms-lite' );
                
$toggle  '<a href="#" class="toggle-smart-tag-display" data-type="other"><i class="fa fa-tags"></i> <span>' esc_html__'Show Smart Tags''wpforms-lite' ) . '</span></a>';
                
$output  $this->field_element'label'$field, array( 'slug' => 'default_value''value' => esc_html__'Default Value''wpforms-lite' ), 'tooltip' => $tooltip'after_tooltip' => $toggle ), false );
                
$output .= $this->field_element'text',  $field, array( 'slug' => 'default_value''value' => $value ), false );
                
$output  $this->field_element'row',   $field, array( 'slug' => 'default_value''content' => $output ), false );
                break;

            
/*
             * Size.
             */
            
case 'size':
                
$value   = ! empty( $field['size'] ) ? esc_attr$field['size'] ) : 'medium';
                
$class   = ! empty( $args['class'] ) ? esc_html$args['class'] ) : '';
                
$tooltip esc_html__'Select the default form field size.''wpforms-lite' );
                
$options = array(
                    
'small'  => esc_html__'Small''wpforms-lite' ),
                    
'medium' => esc_html__'Medium''wpforms-lite' ),
                    
'large'  => esc_html__'Large''wpforms-lite' ),
                );
                
$output  $this->field_element'label',  $field, array( 'slug' => 'size''value' => esc_html__'Field Size''wpforms-lite' ), 'tooltip' => $tooltip ), false );
                
$output .= $this->field_element'select'$field, array( 'slug' => 'size''value' => $value'options' => $options ), false );
                
$output  $this->field_element'row',    $field, array( 'slug' => 'size''content' => $output'class' => $class ), false );
                break;

            
/*
             * Advanced Options markup.
             */
            
case 'advanced-options':
                
$markup = ! empty( $args['markup'] ) ? $args['markup'] : 'open';
                if ( 
'open' === $markup ) {
                    
$override apply_filters'wpforms_advanced_options_override'false );
                    
$override = ! empty( $override ) ? 'style="display:' $override ';"' '';
                    
$output   sprintf'<div class="wpforms-field-option-group wpforms-field-option-group-advanced wpforms-hide" id="wpforms-field-option-advanced-%d" %s>'$field['id'], $override );
                    
$output  .= sprintf'<a href="#" class="wpforms-field-option-group-toggle">%s <i class="fa fa-angle-right"></i></a>'esc_html__'Advanced Options''wpforms-lite' ) );
                    
$output  .= '<div class="wpforms-field-option-group-inner">';
                } else {
                    
$output '</div></div>';
                }
                break;

            
/*
             * Placeholder.
             */
            
case 'placeholder':
                
$value   = ! empty( $field['placeholder'] ) ? esc_attr$field['placeholder'] ) : '';
                
$tooltip esc_html__'Enter text for the form field placeholder.''wpforms-lite' );
                
$output  $this->field_element'label'$field, array( 'slug' => 'placeholder''value' => esc_html__'Placeholder Text''wpforms-lite' ), 'tooltip' => $tooltip ), false );
                
$output .= $this->field_element'text',  $field, array( 'slug' => 'placeholder''value' => $value ), false );
                
$output  $this->field_element'row',   $field, array( 'slug' => 'placeholder''content' => $output ), false );
                break;

            
/*
             * CSS classes.
             */
            
case 'css':
                
$toggle  '';
                
$value   = ! empty( $field['css'] ) ? esc_attr$field['css'] ) : '';
                
$tooltip esc_html__'Enter CSS class names for the form field container. Class names should be separated with spaces.''wpforms-lite' );
                if ( 
'pagebreak' !== $field['type'] ) {
                    
$toggle '<a href="#" class="toggle-layout-selector-display"><i class="fa fa-th-large"></i> <span>' esc_html__'Show Layouts''wpforms-lite' ) . '</span></a>';
                }
                
// Build output.
                
$output  $this->field_element'label'$field, array( 'slug' => 'css''value' => esc_html__'CSS Classes''wpforms-lite' ), 'tooltip' => $tooltip'after_tooltip' => $toggle ), false );
                
$output .= $this->field_element'text'$field, array( 'slug' => 'css''value' => $value ), false );
                
$output  $this->field_element'row'$field, array( 'slug' => 'css''content' => $output ), false );
                break;

            
/*
             * Hide Label.
             */
            
case 'label_hide':
                
$value   = isset( $field['label_hide'] ) ? $field['label_hide'] : '0';
                
$tooltip esc_html__'Check this option to hide the form field label.''wpforms-lite' );
                
// Build output.
                
$output $this->field_element'checkbox'$field, array( 'slug' => 'label_hide''value' => $value'desc' => esc_html__'Hide Label''wpforms-lite' ), 'tooltip' => $tooltip ), false );
                
$output $this->field_element'row',  $field, array( 'slug' => 'label_hide''content' => $output ), false );
                break;

            
/*
             * Hide Sub-Labels.
             */
            
case 'sublabel_hide':
                
$value   = isset( $field['sublabel_hide'] ) ? $field['sublabel_hide'] : '0';
                
$tooltip esc_html__'Check this option to hide the form field sub-label.''wpforms-lite' );
                
// Build output.
                
$output $this->field_element'checkbox'$field, array( 'slug' => 'sublabel_hide''value' => $value'desc' => esc_html__'Hide Sub-Labels''wpforms-lite' ), 'tooltip' => $tooltip ), false );
                
$output $this->field_element'row'$field, array( 'slug' => 'sublabel_hide''content' => $output ), false );
                break;

            
/*
             * Input Columns.
             */
            
case 'input_columns':
                
$value   = ! empty( $field['input_columns'] ) ? esc_attr$field['input_columns'] ) : '';
                
$tooltip esc_html__'Select the layout for displaying field choices.''wpforms-lite' );
                
$options = array(
                    
''       => esc_html__'One Column''wpforms-lite' ),
                    
'2'      => esc_html__'Two Columns''wpforms-lite' ),
                    
'3'      => esc_html__'Three Columns''wpforms-lite' ),
                    
'inline' => esc_html__'Inline''wpforms-lite' ),
                );
                
$output  $this->field_element'label'$field, array( 'slug' => 'input_columns''value' => esc_html__'Choice Layout''wpforms-lite' ), 'tooltip' => $tooltip ), false );
                
$output .= $this->field_element'select'$field, array( 'slug' => 'input_columns''value' => $value'options' => $options ), false );
                
$output  $this->field_element'row'$field, array( 'slug' => 'input_columns''content' => $output ), false );
                break;

            
/*
             * Dynamic Choices.
             */
            
case 'dynamic_choices':
                
$value   = ! empty( $field['dynamic_choices'] ) ? esc_attr$field['dynamic_choices'] ) : '';
                
$tooltip esc_html__'Select auto-populate method to use.''wpforms-lite' );
                
$options = array(
                    
''          => esc_html__'Off''wpforms-lite' ),
                    
'post_type' => esc_html__'Post Type''wpforms-lite' ),
                    
'taxonomy'  => esc_html__'Taxonomy''wpforms-lite' ),
                );
                
$output  $this->field_element'label'$field, array( 'slug' => 'dynamic_choices''value' => esc_html__'Dynamic Choices''wpforms-lite' ), 'tooltip' => $tooltip ), false );
                
$output .= $this->field_element'select'$field, array( 'slug' => 'dynamic_choices''value' => $value'options' => $options ), false );
                
$output  $this->field_element'row'$field, array( 'slug' => 'dynamic_choices''content' => $output ), false );
                break;

            
/*
             * Dynamic Choices Source.
             */
            
case 'dynamic_choices_source':
                
$output '';
                
$type   = ! empty( $field['dynamic_choices'] ) ? esc_attr$field['dynamic_choices'] ) : '';

                if ( ! empty( 
$type ) ) {

                    
$type_name '';
                    
$items     = array();

                    if ( 
'post_type' === $type ) {

                        
$type_name esc_html__'Post Type''wpforms-lite' );
                        
$items     get_post_types(
                            array(
                                
'public' => true,
                            ),
                            
'objects'
                        
);
                        unset( 
$items['attachment'] );

                    } elseif ( 
'taxonomy' === $type ) {

                        
$type_name esc_html__'Taxonomy''wpforms-lite' );
                        
$items     get_taxonomies(
                            array(
                                
'public' => true,
                            ),
                            
'objects'
                        
);
                        unset( 
$items['post_format'] );
                    }

                    
/* translators: %s - dynamic source type name. */
                    
$tooltip sprintfesc_html__'Select %s to use for auto-populating field choices.''wpforms-lite' ), $type_name );
                    
/* translators: %s - dynamic source type name. */
                    
$label   sprintfesc_html__'Dynamic %s Source''wpforms-lite' ), $type_name );
                    
$options = array();
                    
$source  = ! empty( $field'dynamic_' $type ] ) ? esc_attr$field'dynamic_' $type ] ) : '';

                    foreach ( 
$items as $key => $item ) {
                        
$options$key ] = $item->labels->name;
                    }

                    
// Field option label.
                    
$option_label $this->field_element(
                        
'label',
                        
$field,
                        array(
                            
'slug'    => 'dynamic_' $type,
                            
'value'   => $label,
                            
'tooltip' => $tooltip,
                        ),
                        
false
                    
);

                    
// Field option select input.
                    
$option_input $this->field_element(
                        
'select',
                        
$field,
                        array(
                            
'slug'    => 'dynamic_' $type,
                            
'options' => $options,
                            
'value'   => $source,
                        ),
                        
false
                    
);

                    
// Field option row (markup) including label and input.
                    
$output $this->field_element(
                        
'row',
                        
$field,
                        array(
                            
'slug'    => 'dynamic_' $type,
                            
'content' => $option_label $option_input,
                        ),
                        
false
                    
);
                } 
// End if().
                
break;
        }

        if ( ! 
$echo ) {
            return 
$output;
        }

        if ( 
in_array$option, array( 'basic-options''advanced-options' ), true ) ) {

            if ( 
'open' === $markup ) {
                
do_action"wpforms_field_options_before_{$option}"$field$this );
            }

            if ( 
'close' === $markup ) {
                
do_action"wpforms_field_options_bottom_{$option}"$field$this );
            }

            echo 
$output// WPCS: XSS ok.

            
if ( 'open' === $markup ) {
                
do_action"wpforms_field_options_top_{$option}"$field$this );
            }

            if ( 
'close' === $markup ) {
                
do_action"wpforms_field_options_after_{$option}"$field$this );
            }
        } else {
            echo 
$output// WPCS: XSS ok.
        
}
    }

    
/**
     * Helper function to create common field options that are used frequently
     * in the field preview.
     *
     * @since 1.0.0
     * @since 1.5.0 Added support for <select> HTML tag for choices.
     * @since 1.6.1 Added multiple select support.
     *
     * @param string $option Field option to render.
     * @param array  $field  Field data and settings.
     * @param array  $args   Field preview arguments.
     * @param bool   $echo   Print or return the value. Print by default.
     *
     * @return mixed Print or return a string.
     */
    
public function field_preview_option$option$field$args = array(), $echo true ) {

        
$output       '';
        
$class        = ! empty( $args['class'] ) ? wpforms_sanitize_classes$args['class'] ) : '';
        
$allowed_tags wpforms_builder_preview_get_allowed_tags();

        switch ( 
$option ) {

            case 
'label':
                
$label  = isset( $field['label'] ) && ! empty( $field['label'] ) ? esc_html$field['label'] ) : '';
                
$output sprintf'<label class="label-title %s"><span class="text">%s</span><span class="required">*</span></label>'$class$label );
                break;

            case 
'description':
                
$description = isset( $field['description'] ) && ! empty( $field['description'] ) ? wp_kses$field['description'], $allowed_tags ) : '';
                
$description strpos$class'nl2br' ) !== false nl2br$description ) : $description;
                
$output      sprintf'<div class="description %s">%s</div>'$class$description );
                break;

            case 
'choices':
                
$fields_w_choices = array( 'checkbox''gdpr-checkbox''select''payment-select''radio''payment-multiple''payment-checkbox' );

                
$values  = ! empty( $field['choices'] ) ? $field['choices'] : $this->defaults;
                
$dynamic = ! empty( $field['dynamic_choices'] ) ? $field['dynamic_choices'] : false;
                
$total   0;

                
/*
                 * Check to see if this field is configured for Dynamic Choices,
                 * either auto populating from a post type or a taxonomy.
                 */
                
if ( ! empty( $field['dynamic_post_type'] ) || ! empty( $field['dynamic_taxonomy'] ) ) {
                    switch ( 
$dynamic ) {
                        case 
'post_type':
                            
// Post type dynamic populating.
                            
$total_obj wp_count_posts$field['dynamic_post_type'] );
                            
$total     = isset( $total_obj->publish ) ? (int) $total_obj->publish 0;
                            
$values    = array();
                            
$posts     wpforms_get_hierarchical_object(
                                
apply_filters(
                                    
'wpforms_dynamic_choice_post_type_args',
                                    array(
                                        
'post_type'      => $field['dynamic_post_type'],
                                        
'posts_per_page' => -1,
                                        
'orderby'        => 'title',
                                        
'order'          => 'ASC',
                                    ),
                                    
$field,
                                    
$this->form_id
                                
),
                                
true
                            
);

                            foreach ( 
$posts as $post ) {
                                
$values[] = array(
                                    
'label' => $post->post_title,
                                );
                            }
                            break;

                        case 
'taxonomy':
                            
// Taxonomy dynamic populating.
                            
$total  = (int) wp_count_terms$field['dynamic_taxonomy'] );
                            
$values = array();
                            
$terms  wpforms_get_hierarchical_object(
                                
apply_filters(
                                    
'wpforms_dynamic_choice_taxonomy_args',
                                    array(
                                        
'taxonomy'   => $field['dynamic_taxonomy'],
                                        
'hide_empty' => false,
                                    ),
                                    
$field,
                                    
$this->form_id
                                
),
                                
true
                            
);

                            foreach ( 
$terms as $term ) {
                                
$values[] = array(
                                    
'label' => $term->name,
                                );
                            }
                            break;
                    }
                }

                
// Notify if dynamic choices source is currently empty.
                
if ( empty( $values ) ) {
                    
$values = array(
                        array(
                            
'label' => esc_html__'(empty)''wpforms-lite' ),
                        ),
                    );
                }

                
// Build output.
                
if ( ! in_array$field['type'], $fields_w_choicestrue ) ) {
                    break;
                }

                switch ( 
$field['type'] ) {
                    case 
'checkbox':
                    case 
'gdpr-checkbox':
                    case 
'payment-checkbox':
                        
$type 'checkbox';
                        break;

                    case 
'select':
                    case 
'payment-select':
                        
$type 'select';
                        break;

                    default:
                        
$type 'radio';
                        break;
                }

                
$list_class  = array( 'primary-input' );
                
$with_images = empty( $field['dynamic_choices'] ) && ! empty( $field['choices_images'] );

                if ( 
$with_images ) {
                    
$list_class[] = 'wpforms-image-choices';
                    
$list_class[] = 'wpforms-image-choices-' sanitize_html_class$field['choices_images_style'] );
                }

                if ( ! empty( 
$class ) ) {
                    
$list_class[] = $class;
                }

                
// Special rules for <select>-based fields.
                
if ( 'select' === $type ) {
                    
$multiple    = ! empty( $field['multiple'] ) ? ' multiple' '';
                    
$placeholder = ! empty( $field['placeholder'] ) ? $field['placeholder'] : '';

                    
$output sprintf(
                        
'<select class="%s"%s disabled>',
                        
wpforms_sanitize_classes$list_classtrue ),
                        
$multiple
                    
);

                    
// Optional placeholder.
                    
if ( ! empty( $placeholder ) ) {
                        
$output .= sprintf(
                            
'<option value="" class="placeholder">%s</option>',
                            
esc_html$placeholder )
                        );
                    }

                    
// Build the select options.
                    
foreach ( $values as $key => $value ) {

                        
$default  = isset( $value['default'] ) ? (bool) $value['default'] : false;
                        
$selected = ! empty( $placeholder ) && empty( $multiple ) ? '' selectedtrue$defaultfalse );

                        
$label = isset( $value['label'] ) ? trim$value['label'] ) : '';
                        
/* translators: %d - Choice item number. */
                        
$label  $label !== '' $label sprintfesc_html__'Choice %d''wpforms-lite' ), (int) $key );
                        
$label .= ! empty( $field['show_price_after_labels'] ) && isset( $value['value'] ) ? ' - ' wpforms_format_amountwpforms_sanitize_amount$value['value'] ), true ) : '';

                        
$output .= sprintf(
                            
'<option value="%2$s" %1$s>%2$s</option>',
                            
$selected,
                            
esc_html$label )
                        );
                    }

                    
$output .= '</select>';
                } else {
                    
// Normal checkbox/radio-based fields.
                    
$output sprintf(
                        
'<ul class="%s">',
                        
wpforms_sanitize_classes$list_classtrue )
                    );

                    foreach ( 
$values as $key => $value ) {

                        
$default     = isset( $value['default'] ) ? $value['default'] : '';
                        
$selected    checked'1'$defaultfalse );
                        
$input_class = array();
                        
$item_class  = array();

                        if ( ! empty( 
$value['default'] ) ) {
                            
$item_class[] = 'wpforms-selected';
                        }

                        if ( 
$with_images ) {
                            
$item_class[] = 'wpforms-image-choices-item';
                        }

                        
$output .= sprintf(
                            
'<li class="%s">',
                            
wpforms_sanitize_classes$item_classtrue )
                        );

                        
$label = isset( $value['label'] ) ? trim$value['label'] ) : '';
                        
/* translators: %d - Choice item number. */
                        
$label  $label !== '' $label sprintfesc_html__'Choice %d''wpforms-lite' ), (int) $key );
                        
$label .= ! empty( $field['show_price_after_labels'] ) && isset( $value['value'] ) ? ' - ' wpforms_format_amountwpforms_sanitize_amount$value['value'] ), true ) : '';

                        if ( 
$with_images ) {

                            if ( 
in_array$field['choices_images_style'], array( 'modern''classic' ), true ) ) {
                                
$input_class[] = 'wpforms-screen-reader-element';
                            }

                            
$output .= '<label>';

                            
$output .= sprintf(
                                
'<span class="wpforms-image-choices-image"><img src="%s" alt="%s"%s></span>',
                                ! empty( 
$value['image'] ) ? esc_url$value['image'] ) : WPFORMS_PLUGIN_URL 'assets/images/placeholder-200x125.png',
                                
esc_attr$value['label'] ),
                                ! empty( 
$value['label'] ) ? ' title="' esc_attr$value['label'] ) . '"' ''
                            
);

                            if ( 
'none' === $field['choices_images_style'] ) {
                                
$output .= '<br>';
                            }

                            
$output .= sprintf(
                                
'<input type="%s" class="%s" %s disabled>',
                                
$type,
                                
wpforms_sanitize_classes$input_classtrue ),
                                
$selected
                            
);

                            
$output .= '<span class="wpforms-image-choices-label">' wp_kses$label$allowed_tags ) . '</span>';

                            
$output .= '</label>';

                        } else {
                            
$output .= sprintf(
                                
'<input type="%s" %s disabled>%s',
                                
$type,
                                
$selected,
                                
wp_kses$label$allowed_tags )
                            );
                        }

                        
$output .= '</li>';
                    }

                    
$output .= '</ul>';
                }

                
/*
                 * Dynamic population is enabled and contains more than 20 items,
                 * include a note about results displayed.
                 */
                
if ( $total 20 ) {
                    
$output .= '<div class="wpforms-alert-dynamic wpforms-alert wpforms-alert-warning">';
                    
$output .= sprintf(
                        
wp_kses(
                            
/* translators: %d - total amount of choices. */
                            
__'Showing the first 20 choices.<br> All %d choices will be displayed when viewing the form.''wpforms-lite' ),
                            array(
                                
'br' => array(),
                            )
                        ),
                        
$total
                    
);
                    
$output .= '</div>';
                }
                break;
        }

        if ( ! 
$echo ) {
            return 
$output;
        }

        echo 
$output// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
    
}

    
/**
     * Create a new field in the admin AJAX editor.
     *
     * @since 1.0.0
     */
    
public function field_new() {

        
// Run a security check.
        
check_ajax_referer'wpforms-builder''nonce' );

        
// Check for permissions.
        
if ( ! wpforms_current_user_can'edit_forms' ) ) {
            die( 
esc_html__'You do not have permission.''wpforms-lite' ) );
        }

        
// Check for form ID.
        
if ( ! isset( $_POST['id'] ) || empty( $_POST['id'] ) ) {
            die( 
esc_html__'No form ID found''wpforms-lite' ) );
        }

        
// Check for field type to add.
        
if ( ! isset( $_POST['type'] ) || empty( $_POST['type'] ) ) {
            die( 
esc_html__'No field type found''wpforms-lite' ) );
        }

        
// Grab field data.
        
$field_args     = ! empty( $_POST['defaults'] ) ? (array) $_POST['defaults'] : array();
        
$field_type     esc_attr$_POST['type'] );
        
$field_id       wpforms()->form->next_field_id$_POST['id'] );
        
$field          = array(
            
'id'          => $field_id,
            
'type'        => $field_type,
            
'label'       => $this->name,
            
'description' => '',
        );
        
$field          wp_parse_args$field_args$field );
        
$field          apply_filters'wpforms_field_new_default'$field );
        
$field_required apply_filters'wpforms_field_new_required'''$field );
        
$field_class    apply_filters'wpforms_field_new_class'''$field );

        
// Field types that default to required.
        
if ( ! empty( $field_required ) ) {
            
$field_required    'required';
            
$field['required'] = '1';
        }

        
// Build Preview.
        
ob_start();
        
$this->field_preview$field );
        
$prev     ob_get_clean();
        
$preview  sprintf'<div class="wpforms-field wpforms-field-%s %s %s" id="wpforms-field-%d" data-field-id="%d" data-field-type="%s">'$field_type$field_required$field_class$field['id'], $field['id'], $field_type );
        if ( 
apply_filters'wpforms_field_new_display_duplicate_button'true$field ) ) {
            
$preview .= sprintf'<a href="#" class="wpforms-field-duplicate" title="%s"><i class="fa fa-files-o" aria-hidden="true"></i></a>'esc_attr__'Duplicate Field''wpforms-lite' ) );
        }
        
$preview .= sprintf'<a href="#" class="wpforms-field-delete" title="%s"><i class="fa fa-trash"></i></a>'esc_attr__'Delete Field''wpforms-lite' ) );
        
$preview .= sprintf'<span class="wpforms-field-helper">%s</span>'esc_html__'Click to edit. Drag to reorder.''wpforms-lite' ) );
        
$preview .= $prev;
        
$preview .= '</div>';

        
// Build Options.
        
$class    apply_filters'wpforms_builder_field_option_class'''$field );
        
$options  sprintf'<div class="wpforms-field-option wpforms-field-option-%s %s" id="wpforms-field-option-%d" data-field-id="%d">'sanitize_html_class$field['type'] ), wpforms_sanitize_classes$class ), (int) $field['id'], (int) $field['id'] );
        
$options .= sprintf'<input type="hidden" name="fields[%d][id]" value="%d" class="wpforms-field-option-hidden-id">'$field['id'], $field['id'] );
        
$options .= sprintf'<input type="hidden" name="fields[%d][type]" value="%s" class="wpforms-field-option-hidden-type">'$field['id'], esc_attr$field['type'] ) );
        
ob_start();
        
$this->field_options$field );
        
$options .= ob_get_clean();
        
$options .= '</div>';

        
// Prepare to return compiled results.
        
wp_send_json_success(
            array(
                
'form_id' => (int) $_POST['id'],
                
'field'   => $field,
                
'preview' => $preview,
                
'options' => $options,
            )
        );
    }

    
/**
     * Display the field input elements on the frontend.
     *
     * @since 1.0.0
     * @since 1.5.0 Converted to abstract method, as it's required for all fields.
     *
     * @param array $field      Field data and settings.
     * @param array $field_atts Field attributes.
     * @param array $form_data  Form data and settings.
     */
    
abstract public function field_display$field$field_atts$form_data );

    
/**
     * Display field input errors if present.
     *
     * @since 1.3.7
     *
     * @param string $key   Input key.
     * @param array  $field Field data and settings.
     */
    
public function field_display_error$key$field ) {

        
// Need an error.
        
if ( empty( $field['properties']['error']['value'][ $key ] ) ) {
            return;
        }

        
printf(
            
'<label class="wpforms-error" for="%s">%s</label>',
            
esc_attr$field['properties']['inputs'][ $key ]['id'] ),
            
esc_html$field['properties']['error']['value'][ $key ] )
        );
    }

    
/**
     * Display field input sublabel if present.
     *
     * @since 1.3.7
     *
     * @param string $key      Input key.
     * @param string $position Sublabel position.
     * @param array  $field    Field data and settings.
     */
    
public function field_display_sublabel$key$position$field ) {

        
// Need a sublabel value.
        
if ( empty( $field['properties']['inputs'][ $key ]['sublabel']['value'] ) ) {
            return;
        }

        
$pos    = ! empty( $field['properties']['inputs'][ $key ]['sublabel']['position'] ) ? $field['properties']['inputs'][ $key ]['sublabel']['position'] : 'after';
        
$hidden = ! empty( $field['properties']['inputs'][ $key ]['sublabel']['hidden'] ) ? 'wpforms-sublabel-hide' '';

        if ( 
$pos !== $position ) {
            return;
        }

        
printf(
            
'<label for="%s" class="wpforms-field-sublabel %s %s">%s</label>',
            
esc_attr$field['properties']['inputs'][ $key ]['id'] ),
            
sanitize_html_class$pos ),
            
$hidden,
            
$field['properties']['inputs'][ $key ]['sublabel']['value']
        );
    }

    
/**
     * Validate field on form submit.
     *
     * @since 1.0.0
     *
     * @param int   $field_id     Field ID.
     * @param mixed $field_submit Field value that was submitted.
     * @param array $form_data    Form data and settings.
     */
    
public function validate$field_id$field_submit$form_data ) {

        
// Basic required check - If field is marked as required, check for entry data.
        
if ( ! empty( $form_data['fields'][ $field_id ]['required'] ) && empty( $field_submit ) && '0' !== (string) $field_submit ) {
            
wpforms()->process->errors$form_data['id'] ][ $field_id ] = wpforms_get_required_label();
        }
    }

    
/**
     * Format and sanitize field.
     *
     * @since 1.0.0
     *
     * @param int   $field_id     Field ID.
     * @param mixed $field_submit Field value that was submitted.
     * @param array $form_data    Form data and settings.
     */
    
public function format$field_id$field_submit$form_data ) {

        if ( 
is_array$field_submit ) ) {
            
$field_submit array_filter$field_submit );
            
$field_submit implode"\r\n"$field_submit );
        }

        
$name = ! empty( $form_data['fields'][ $field_id ]['label'] ) ? sanitize_text_field$form_data['fields'][ $field_id ]['label'] ) : '';

        
// Sanitize but keep line breaks.
        
$value wpforms_sanitize_textarea_field$field_submit );

        
wpforms()->process->fields$field_id ] = array(
            
'name'  => $name,
            
'value' => $value,
            
'id'    => absint$field_id ),
            
'type'  => $this->type,
        );
    }

    
/**
     * Get field name for ajax error message.
     *
     * @since 1.6.3
     *
     * @param string $name  Field name for error triggered.
     * @param array  $field Field settings.
     * @param array  $props List of properties.
     * @param string $error Error message.
     *
     * @return string
     */
    
public function ajax_error_field_name$name$field$props$error ) {

        if ( 
$name ) {
            return 
$name;
        }
        
$input = isset( $props['inputs']['primary'] ) ? $props['inputs']['primary'] : end$props['inputs'] );

        return (string) isset( 
$input['attr']['name'] ) ? $input['attr']['name'] : '';
    }

    
/**
     * Enqueue Choicesjs script and config.
     *
     * @param array $forms Forms on the current page.
     *
     * @since 1.6.3
     */
    
protected function enqueue_choicesjs_once$forms ) {

        if ( 
wpforms()->frontend->is_choicesjs_enqueued ) {
            return;
        }

        
wp_enqueue_script(
            
'wpforms-choicesjs',
            
WPFORMS_PLUGIN_URL 'assets/js/choices.min.js',
            array(),
            
'9.0.1',
            
true
        
);

        
$config = [
            
'removeItemButton'  => true,
            
'shouldSort'        => false,
            
'loadingText'       => esc_html__'Loading...''wpforms-lite' ),
            
'noResultsText'     => esc_html__'No results found.''wpforms-lite' ),
            
'noChoicesText'     => esc_html__'No choices to choose from.''wpforms-lite' ),
            
'itemSelectText'    => esc_attr__'Press to select.''wpforms-lite' ),
            
'uniqueItemText'    => esc_html__'Only unique values can be added.''wpforms-lite' ),
            
'customAddItemText' => esc_html__'Only values matching specific conditions can be added.''wpforms-lite' ),
        ];

        
// Allow theme/plugin developers to modify the provided or add own Choices.js settings.
        
$config apply_filters'wpforms_field_select_choicesjs_config'$config$forms$this );

        
wp_localize_script(
            
'wpforms-choicesjs',
            
'wpforms_choicesjs_config',
            
$config
        
);

        
wpforms()->frontend->is_choicesjs_enqueued true;
    }

    
/**
     * Whether a Choicesjs search area should be shown.
     *
     * @since 1.6.4
     *
     * @param int $choices_count Choices amount.
     *
     * @return bool
     */
    
protected function is_choicesjs_search_enabled$choices_count ) {

        
// We should auto hide/remove search, if less than 8 choices.
        
return $choices_count >= (int) apply_filters'wpforms_field_choicesjs_search_enabled_items_min');
    }
}
x

Windows NT KPTV 6.2 build 9200 (Windows Server 2012 Datacenter Edition) i586