PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 2.10.1
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v2.10.1
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 / Conversational / Fields / CheckBoxField.php

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

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