PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 2.15.3
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v2.15.3
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 2.10.2 All 137 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.15.3, at includes/Frontend/Form/View/Theme/Fields/CheckBoxField.php

167 lines 6.5 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='disabled'";
51 }
52
53 $checkBoxOptions .= <<<CHECKBOXOPTIONS
54 <div
55 {$fieldHelpers->getCustomAttributes('cw')}
56 class="{$fieldHelpers->getAtomicCls('cw')} {$fieldHelpers->getCustomClasses('cw')}"
57 >
58 <input
59 id="{$rowID}-{$contentCount}-chk-{$key}"
60 type="checkbox"
61 class="{$fieldHelpers->getAtomicCls('ci')} {$fieldHelpers->getCustomClasses('ci')}"
62 {$disabled}
63 value="{$value}"
64 {$check}
65 {$req}
66 {$name}
67 />
68 <label
69 {$fieldHelpers->getCustomAttributes('cl')}
70 data-cl
71 for="{$rowID}-{$contentCount}-chk-{$key}"
72 class="{$fieldHelpers->getAtomicCls('cl')} {$fieldHelpers->getCustomClasses('cl')}"
73 >
74 <span
75 {$fieldHelpers->getCustomAttributes('bx')}
76 data-bx
77 class="{$fieldHelpers->getAtomicCls('bx')} {$fieldHelpers->getCustomClasses('bx')}"
78 >
79 <svg width="12" height="10" viewBox="0 0 12 10" class="{$fieldHelpers->getAtomicCls('svgwrp')} {$fieldHelpers->getCustomClasses('svgwrp')}">
80 <use data-ck-icn href="$href" class="{$fieldHelpers->getAtomicCls('ck-icn')} {$fieldHelpers->getCustomClasses('ck-icn')}" />
81 </svg>
82 </span>
83 <span
84 {$fieldHelpers->getCustomAttributes('ct')}
85 class="{$fieldHelpers->getAtomicCls('ct')} {$fieldHelpers->getCustomClasses('ct')}"
86 >
87 {$fieldHelpers->kses_post($fieldHelpers->renderHTMR($opt->lbl))}
88 </span>
89 </label>
90 </div>
91 CHECKBOXOPTIONS;
92 }
93 }
94
95 //Other Option
96 $optCount = property_exists($field, 'opt') ? count($field->opt) : 0;
97 $inputPh = isset($field->otherInpPh) ? "placeholder='{$fieldHelpers->esc_attr($field->otherInpPh)}'" : "placeholder='Other...'";
98 $inpReq = isset($field->valid->otherOptReq) ? ($field->valid->otherOptReq ? 'required' : '') : '';
99 if (property_exists($field, 'addOtherOpt') && $field->addOtherOpt) {
100 $checkBoxOptions .= <<<CHECKBOXOPTIONS
101 <div
102 {$fieldHelpers->getCustomAttributes('cw')}
103 class="{$fieldHelpers->getAtomicCls('cw')} {$fieldHelpers->getCustomClasses('cw')}"
104 >
105 <input
106 id="{$rowID}-{$contentCount}-chk-{$optCount}"
107 data-oopt="{$rowID}"
108 type="checkbox"
109 class="{$fieldHelpers->getAtomicCls('ci')} {$fieldHelpers->getCustomClasses('ci')}"
110 {$disabled}
111 value=""
112 {$name}
113 />
114 <label
115 {$fieldHelpers->getCustomAttributes('cl')}
116 data-cl
117 for="{$rowID}-{$contentCount}-chk-{$optCount}"
118 class="{$fieldHelpers->getAtomicCls('cl')} {$fieldHelpers->getCustomClasses('cl')}"
119 >
120 <span
121 {$fieldHelpers->getCustomAttributes('ck')}
122 data-bx
123 class="{$fieldHelpers->getAtomicCls('bx')} {$fieldHelpers->getAtomicCls('ck')} {$fieldHelpers->getCustomClasses('ck')}"
124 >
125 <svg width="12" height="10" viewBox="0 0 12 10" class="{$fieldHelpers->getAtomicCls('svgwrp')} {$fieldHelpers->getCustomClasses('svgwrp')}">
126 <use data-ck-icn href="#$rowID-ck-svg" class="{$fieldHelpers->getAtomicCls('ck-icn')} {$fieldHelpers->getCustomClasses('ck-icn')}" />
127 </svg>
128 </span>
129 <span
130 {$fieldHelpers->getCustomAttributes('ct')}
131 class="{$fieldHelpers->getAtomicCls('ct')} {$fieldHelpers->getCustomClasses('ct')}"
132 >
133 Other..
134 </span>
135 </label>
136 <div data-oinp-wrp class="{$fieldHelpers->getAtomicCls('other-inp-wrp')}">
137 <input
138 data-bf-other-inp='{$rowID}-chk-{$optCount}'
139 type="text"
140 class="{$fieldHelpers->getAtomicCls('other-inp')} {$fieldHelpers->getCustomClasses('other-inp')}"
141 {$inpReq}
142 {$inputPh}
143 />
144 </div>
145 </div>
146 CHECKBOXOPTIONS;
147 }
148
149 return <<<CHECKBOXFIELD
150 <div
151 {$fieldHelpers->getCustomAttributes('cc')}
152 class="{$fieldHelpers->getAtomicCls('cc')} {$fieldHelpers->getCustomClasses('cc')}"
153 >
154 <svg class="{$fieldHelpers->getAtomicCls('cks')}">
155 <symbol id="{$rowID}-ck-svg" viewBox="0 0 12 10">
156 <polyline
157 class="{$fieldHelpers->getAtomicCls('ck-svgline')}"
158 points="1.5 6 4.5 9 10.5 1"
159 ></polyline>
160 </symbol>
161 </svg>
162 {$checkBoxOptions}
163 </div>
164 CHECKBOXFIELD;
165 }
166 }
167