PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 3.2.2
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v3.2.2
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 3.2.2, at includes/Frontend/Form/View/Theme/Fields/CheckBoxField.php

188 lines 7.6 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 (is_object($field) && property_exists($field, 'opt') && is_countable($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 .= '
58 <div
59 ' . $fieldHelpers->getCustomAttributes('cw') . '
60 class="' . $fieldHelpers->getAtomicCls('cw') . ' ' . $fieldHelpers->getCustomClasses('cw') . '"
61 >
62 <input
63 id="' . $rowID . '-' . $contentCount . '-chk-' . $key . '"
64 type="checkbox"
65 class="' . $fieldHelpers->getAtomicCls('ci') . ' ' . $fieldHelpers->getCustomClasses('ci') . '"
66 ' . $disabled . '
67 value="' . $value . '"
68 ' . $check . '
69 ' . $req . '
70 ' . $name . '
71 />
72 <label
73 ' . $fieldHelpers->getCustomAttributes('cl') . '
74 data-cl
75 for="' . $rowID . '-' . $contentCount . '-chk-' . $key . '"
76 class="' . $fieldHelpers->getAtomicCls('cl') . ' ' . $fieldHelpers->getCustomClasses('cl') . '"
77 >
78 <span
79 ' . $fieldHelpers->getCustomAttributes('bx') . '
80 data-bx
81 class="' . $fieldHelpers->getAtomicCls('bx') . ' ' . $fieldHelpers->getCustomClasses('bx') . '"
82 >
83 <svg width="12" height="10" viewBox="0 0 12 10" class="' . $fieldHelpers->getAtomicCls('svgwrp') . ' ' . $fieldHelpers->getCustomClasses('svgwrp') . '" aria-hidden="true">
84 <use data-ck-icn href="' . $href . '" class="' . $fieldHelpers->getAtomicCls('ck-icn') . ' ' . $fieldHelpers->getCustomClasses('ck-icn') . '" />
85 </svg>
86 </span>
87 <span
88 ' . $fieldHelpers->getCustomAttributes('ct') . '
89 class="' . $fieldHelpers->getAtomicCls('ct') . ' ' . $fieldHelpers->getCustomClasses('ct') . '"
90 >
91 ' . $fieldHelpers->kses_post($fieldHelpers->renderHTMR($opt->lbl)) . '
92 </span>
93 </label>
94 </div>';
95 }
96 }
97
98 //Other Option
99 $optCount = isset($field->opt) && is_countable($field->opt) ? count($field->opt) : 0;
100 $inpReq = isset($field->valid->otherOptReq) ? ($field->valid->otherOptReq ? 'required' : '') : '';
101 $otherOptLbl = !empty($field->otherOptLbl) ? $field->otherOptLbl : __('Other...', 'bit-form');
102 $inputPh = isset($field->otherInpPh) ? "placeholder='{$fieldHelpers->esc_attr($field->otherInpPh)}'" : "placeholder='{$otherOptLbl}'";
103 if (property_exists($field, 'addOtherOpt') && $field->addOtherOpt) {
104 $checkBoxOptions .=
105 '<div
106 ' . $fieldHelpers->getCustomAttributes('cw') . '
107 class="' . $fieldHelpers->getAtomicCls('cw') . ' ' . $fieldHelpers->getCustomClasses('cw') . '"
108 >
109 <input
110 id="' . $rowID . '-' . $contentCount . '-chk-' . $optCount . '"
111 data-oopt="' . $rowID . '"
112 type="checkbox"
113 class="' . $fieldHelpers->getAtomicCls('ci') . ' ' . $fieldHelpers->getCustomClasses('ci') . '"
114 ' . $disabled . '
115 value=""
116 ' . $name . '
117 />
118 <label
119 ' . $fieldHelpers->getCustomAttributes('cl') . '
120 data-cl
121 for="' . $rowID . '-' . $contentCount . '-chk-' . $optCount . '"
122 class="' . $fieldHelpers->getAtomicCls('cl') . ' ' . $fieldHelpers->getCustomClasses('cl') . '"
123 >
124 <span
125 ' . $fieldHelpers->getCustomAttributes('ck') . '
126 data-bx
127 class="' . $fieldHelpers->getAtomicCls('bx') . ' ' . $fieldHelpers->getAtomicCls('ck') . ' ' . $fieldHelpers->getCustomClasses('ck') . '"
128 >
129 <svg width="12" height="10" viewBox="0 0 12 10" class="' . $fieldHelpers->getAtomicCls('svgwrp') . ' ' . $fieldHelpers->getCustomClasses('svgwrp') . '" aria-hidden="true">
130 <use data-ck-icn href="#' . $rowID . '-ck-svg" class="' . $fieldHelpers->getAtomicCls('ck-icn') . ' ' . $fieldHelpers->getCustomClasses('ck-icn') . '" />
131 </svg>
132 </span>
133 <span
134 ' . $fieldHelpers->getCustomAttributes('ct') . '
135 class="' . $fieldHelpers->getAtomicCls('ct') . ' ' . $fieldHelpers->getCustomClasses('ct') . '"
136 >
137 ' . $otherOptLbl . '
138 </span>
139 </label>
140 <div data-oinp-wrp class="' . $fieldHelpers->getAtomicCls('other-inp-wrp') . '">
141 <input
142 data-bf-other-inp="' . $rowID . '-chk-' . $optCount . '"
143 type="text"
144 class="' . $fieldHelpers->getAtomicCls('other-inp') . ' ' . $fieldHelpers->getCustomClasses('other-inp') . '"
145 ' . $inpReq . '
146 ' . $inputPh . '
147 />
148 </div>
149 </div>';
150 }
151
152 $labelId = $fieldHelpers->getLabelId();
153 $ariaDescribedBy = $fieldHelpers->ariaDescribedBy();
154 $ariaRequired = $fieldHelpers->ariaRequired();
155
156 return sprintf(
157 '<div
158 %1$s
159 class="%2$s %3$s"
160 role="group"
161 aria-labelledby="%4$s"
162 %5$s
163 %6$s
164 >
165 <svg class="%7$s" aria-hidden="true">
166 <symbol id="%8$s-ck-svg" viewBox="0 0 12 10">
167 <polyline
168 class="%9$s"
169 points="1.5 6 4.5 9 10.5 1"
170 ></polyline>
171 </symbol>
172 </svg>
173 %10$s
174 </div>',
175 $fieldHelpers->getCustomAttributes('cc'),
176 $fieldHelpers->getAtomicCls('cc'),
177 $fieldHelpers->getCustomClasses('cc'),
178 $labelId,
179 $ariaDescribedBy,
180 $ariaRequired,
181 $fieldHelpers->getAtomicCls('cks'),
182 $rowID,
183 $fieldHelpers->getAtomicCls('ck-svgline'),
184 $checkBoxOptions
185 );
186 }
187 }
188