PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 2.21.13
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v2.21.13
3.3.1 V-3.3.0 3.2.2 3.2.1 3.2.0 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 V3.0.3 V3.0.2 -3.0.1 V_3.0.0 1.1.1 1.1.8 1.2 1.3 1.4 1.4.18 1.5.2 1.9 2.0 2.10.0 2.10.1 All 138 releases
bit-form / includes / Frontend / Form / View / Theme / Fields / CheckBoxField.php

CheckBoxField.php in Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder 2.21.13, at includes/Frontend/Form/View/Theme/Fields/CheckBoxField.php

175 lines 7.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace BitCode\BitForm\Frontend\Form\View\Theme\Fields;
4
5 use BitCode\BitForm\Core\Util\FrontendHelpers;
6
7 class CheckBoxField
8 {
9 public static function init($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error, $value)
10 {
11 $inputWrapper = new ClassicInputWrapper($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error, $value);
12 $input = self::field($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error, $value);
13 return $inputWrapper->wrapper($input);
14 }
15
16 private static function field($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error, $value)
17 {
18 $fieldHelpers = new ClassicFieldHelpers($field, $rowID, $form_atomic_Cls_map);
19
20 $req = $fieldHelpers->required();
21 $name = $fieldHelpers->name();
22 $checkBoxOptions = '';
23 $bfFrontendFormIds = FrontendHelpers::$bfFrontendFormIds;
24 $contentCount = count($bfFrontendFormIds);
25
26 if (property_exists($field, 'opt') && count($field->opt) > 0) {
27 if (isset($field->val) && false !== strpos($field->val, BITFORMS_BF_SEPARATOR)) {
28 $defaultValues = explode(BITFORMS_BF_SEPARATOR, $field->val);
29 } else {
30 $defaultValues = isset($field->val) ? explode(',', $field->val) : [];
31 }
32 foreach ($field->opt as $key => $opt) {
33 $value = isset($opt->val) ? $opt->val : $opt->lbl;
34 $check = '';
35 $req = '';
36 $disabled = '';
37 $href = htmlentities("#$rowID-ck-svg");
38 if ($fieldHelpers->property_exists_nested($opt, 'check', true)) {
39 $check = 'checked';
40 } else {
41 if (in_array($value, $defaultValues)) {
42 $check = 'checked';
43 }
44 }
45 if ($fieldHelpers->property_exists_nested($opt, 'req', true)) {
46 $req = 'required';
47 }
48 if ($fieldHelpers->property_exists_nested($field, 'valid->disabled', true)
49 || $fieldHelpers->property_exists_nested($opt, 'disabled', true)) {
50 $disabled = 'disabled';
51 }
52
53 if (isset($field->mx) && !empty($field->valid->disableOnMax) && !$check && ((int) $field->mx <= count($defaultValues))) {
54 $disabled = 'disabled';
55 }
56
57 $checkBoxOptions .= '<div
58 ' . $fieldHelpers->getCustomAttributes('cw') . '
59 class="' . $fieldHelpers->getAtomicCls('cw') . ' ' . $fieldHelpers->getCustomClasses('cw') . '"
60 >
61 <input
62 id="' . $rowID . '-' . $contentCount . '-chk-' . $key . '"
63 type="checkbox"
64 class="' . $fieldHelpers->getAtomicCls('ci') . ' ' . $fieldHelpers->getCustomClasses('ci') . '"
65 ' . $disabled . '
66 value="' . $value . '"
67 ' . $check . '
68 ' . $req . '
69 ' . $name . '
70 />
71 <label
72 ' . $fieldHelpers->getCustomAttributes('cl') . '
73 data-cl
74 for="' . $rowID . '-' . $contentCount . '-chk-' . $key . '"
75 class="' . $fieldHelpers->getAtomicCls('cl') . ' ' . $fieldHelpers->getCustomClasses('cl') . '"
76 >
77 <span
78 ' . $fieldHelpers->getCustomAttributes('bx') . '
79 data-bx
80 class="' . $fieldHelpers->getAtomicCls('bx') . ' ' . $fieldHelpers->getCustomClasses('bx') . '"
81 >
82 <svg width="12" height="10" viewBox="0 0 12 10" class="' . $fieldHelpers->getAtomicCls('svgwrp') . ' ' . $fieldHelpers->getCustomClasses('svgwrp') . '">
83 <use data-ck-icn href="' . $href . '" class="' . $fieldHelpers->getAtomicCls('ck-icn') . ' ' . $fieldHelpers->getCustomClasses('ck-icn') . '" />
84 </svg>
85 </span>
86 <span
87 ' . $fieldHelpers->getCustomAttributes('ct') . '
88 class="' . $fieldHelpers->getAtomicCls('ct') . ' ' . $fieldHelpers->getCustomClasses('ct') . '"
89 >
90 ' . $fieldHelpers->kses_post($fieldHelpers->renderHTMR($opt->lbl)) . '
91 </span>
92 </label>
93 </div>';
94 }
95 }
96
97 //Other Option
98 $optCount = property_exists($field, 'opt') ? count($field->opt) : 0;
99 $inpReq = isset($field->valid->otherOptReq) ? ($field->valid->otherOptReq ? 'required' : '') : '';
100 $otherOptLbl = !empty($field->otherOptLbl) ? $field->otherOptLbl : __('Other...', 'bit-form');
101 $inputPh = isset($field->otherInpPh) ? "placeholder='{$fieldHelpers->esc_attr($field->otherInpPh)}'" : "placeholder='{$otherOptLbl}'";
102 if (property_exists($field, 'addOtherOpt') && $field->addOtherOpt) {
103 $checkBoxOptions .= '<div
104 ' . $fieldHelpers->getCustomAttributes('cw') . '
105 class="' . $fieldHelpers->getAtomicCls('cw') . ' ' . $fieldHelpers->getCustomClasses('cw') . '"
106 >
107 <input
108 id="' . $rowID . '-' . $contentCount . '-chk-' . $optCount . '"
109 data-oopt="' . $rowID . '"
110 type="checkbox"
111 class="' . $fieldHelpers->getAtomicCls('ci') . ' ' . $fieldHelpers->getCustomClasses('ci') . '"
112 ' . $disabled . '
113 value=""
114 ' . $name . '
115 />
116 <label
117 ' . $fieldHelpers->getCustomAttributes('cl') . '
118 data-cl
119 for="' . $rowID . '-' . $contentCount . '-chk-' . $optCount . '"
120 class="' . $fieldHelpers->getAtomicCls('cl') . ' ' . $fieldHelpers->getCustomClasses('cl') . '"
121 >
122 <span
123 ' . $fieldHelpers->getCustomAttributes('ck') . '
124 data-bx
125 class="' . $fieldHelpers->getAtomicCls('bx') . ' ' . $fieldHelpers->getAtomicCls('ck') . ' ' . $fieldHelpers->getCustomClasses('ck') . '"
126 >
127 <svg width="12" height="10" viewBox="0 0 12 10" class="' . $fieldHelpers->getAtomicCls('svgwrp') . ' ' . $fieldHelpers->getCustomClasses('svgwrp') . '">
128 <use data-ck-icn href="#' . $rowID . '-ck-svg" class="' . $fieldHelpers->getAtomicCls('ck-icn') . ' ' . $fieldHelpers->getCustomClasses('ck-icn') . '" />
129 </svg>
130 </span>
131 <span
132 ' . $fieldHelpers->getCustomAttributes('ct') . '
133 class="' . $fieldHelpers->getAtomicCls('ct') . ' ' . $fieldHelpers->getCustomClasses('ct') . '"
134 >
135 ' . $otherOptLbl . '
136 </span>
137 </label>
138 <div data-oinp-wrp class="' . $fieldHelpers->getAtomicCls('other-inp-wrp') . '">
139 <input
140 data-bf-other-inp="' . $rowID . '-chk-' . $optCount . '"
141 type="text"
142 class="' . $fieldHelpers->getAtomicCls('other-inp') . ' ' . $fieldHelpers->getCustomClasses('other-inp') . '"
143 ' . $inpReq . '
144 ' . $inputPh . '
145 />
146 </div>
147 </div>';
148 }
149
150 return sprintf(
151 '<div
152 %1$s
153 class="%2$s %3$s"
154 >
155 <svg class="%4$s">
156 <symbol id="%5$s-ck-svg" viewBox="0 0 12 10">
157 <polyline
158 class="%6$s"
159 points="1.5 6 4.5 9 10.5 1"
160 ></polyline>
161 </symbol>
162 </svg>
163 %7$s
164 </div>',
165 $fieldHelpers->getCustomAttributes('cc'),
166 $fieldHelpers->getAtomicCls('cc'),
167 $fieldHelpers->getCustomClasses('cc'),
168 $fieldHelpers->getAtomicCls('cks'),
169 $rowID,
170 $fieldHelpers->getAtomicCls('ck-svgline'),
171 $checkBoxOptions
172 );
173 }
174 }
175