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

185 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\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 $ariaDescribedBy = $fieldHelpers->ariaDescribedBy();
23 $ariaRequired = $fieldHelpers->ariaRequired();
24 $labelId = $fieldHelpers->getLabelId();
25 $checkBoxOptions = '';
26 $bfFrontendFormIds = FrontendHelpers::$bfFrontendFormIds;
27 $contentCount = count($bfFrontendFormIds);
28
29 if (is_object($field) && property_exists($field, 'opt') && is_countable($field->opt) && count($field->opt) > 0) {
30 if (isset($field->val) && false !== strpos($field->val, BITFORMS_BF_SEPARATOR)) {
31 $defaultValues = explode(BITFORMS_BF_SEPARATOR, $field->val);
32 } else {
33 $defaultValues = isset($field->val) ? explode(',', $field->val) : [];
34 }
35 foreach ($field->opt as $key => $opt) {
36 $value = isset($opt->val) ? $opt->val : $opt->lbl;
37 $check = '';
38 $req = '';
39 $disabled = '';
40 $keyChar = chr(65 + $key);
41 $href = htmlentities("#$rowID-ck-svg");
42 if ($fieldHelpers->property_exists_nested($opt, 'check', true)) {
43 $check = 'checked';
44 } else {
45 if (in_array($value, $defaultValues)) {
46 $check = 'checked';
47 }
48 }
49 if ($fieldHelpers->property_exists_nested($opt, 'req', true)) {
50 $req = 'required';
51 }
52 if (
53 $fieldHelpers->property_exists_nested($field, 'valid->disabled', true)
54 || $fieldHelpers->property_exists_nested($opt, 'disabled', true)
55 ) {
56 $disabled = "disabled='disabled'";
57 }
58
59 $checkBoxOptions .=
60 '<div
61 ' . $fieldHelpers->getCustomAttributes('cw') . '
62 class="' . $fieldHelpers->getConversationalCls('cw') . ' ' . $fieldHelpers->getCustomClasses('cw') . '"
63 >
64 <input
65 id="' . $rowID . '-' . $contentCount . '-chk-' . $key . '"
66 type="checkbox"
67 class="' . $fieldHelpers->getConversationalCls('ci') . ' ' . $fieldHelpers->getCustomClasses('ci') . '"
68 ' . $disabled . '
69 value="' . $value . '"
70 ' . $check . '
71 ' . $req . '
72 ' . $name . '
73 />
74
75 <label
76 ' . $fieldHelpers->getCustomAttributes('cl') . '
77 data-cl
78 for="' . $rowID . '-' . $contentCount . '-chk-' . $key . '"
79 class="' . $fieldHelpers->getConversationalCls('cl') . ' ' . $fieldHelpers->getCustomClasses('cl') . '"
80 >
81 <span
82 ' . $fieldHelpers->getCustomAttributes('bx') . '
83 data-bx
84 class="' . $fieldHelpers->getConversationalCls('bx') . ' ' . $fieldHelpers->getCustomClasses('bx') . '"
85 >
86 <span class="' . $fieldHelpers->getConversationalCls('opt-key-lbl') . '">Key</span>
87 <span class="' . $fieldHelpers->getConversationalCls('opt-key') . '">' . $keyChar . '</span>
88 </span>
89 <span
90 ' . $fieldHelpers->getCustomAttributes('ct') . '
91 class="' . $fieldHelpers->getConversationalCls('ct') . ' ' . $fieldHelpers->getCustomClasses('ct') . '"
92 >
93 ' . $fieldHelpers->kses_post($fieldHelpers->renderHTMR($opt->lbl)) . '
94 </span>
95 </label>
96 </div>
97 ';
98 }
99 }
100
101 //Other Option
102 $optCount = isset($field->opt) && is_countable($field->opt) ? count($field->opt) : 0;
103 $otherOptLbl = !empty($field->otherOptLbl) ? $field->otherOptLbl : __('Other...', 'bit-form');
104 $inputPh = isset($field->otherInpPh) ? "placeholder='{$fieldHelpers->esc_attr($field->otherInpPh)}'" : "placeholder='Other...'";
105 $inpReq = isset($field->valid->otherOptReq) ? ($field->valid->otherOptReq ? 'required' : '') : '';
106 if (property_exists($field, 'addOtherOpt') && $field->addOtherOpt) {
107 $keyChar = chr(65 + count($field->opt));
108 $checkBoxOptions .=
109 ' <div
110 ' . $fieldHelpers->getCustomAttributes('cw') . '
111 class="' . $fieldHelpers->getConversationalCls('cw') . ' ' . $fieldHelpers->getCustomClasses('cw') . '"
112 >
113 <input
114 id="' . $rowID . '-' . $contentCount . '-chk-' . $optCount . '"
115 data-oopt="' . $rowID . '"
116 type="checkbox"
117 class="' . $fieldHelpers->getConversationalCls('ci') . ' ' . $fieldHelpers->getCustomClasses('ci') . '"
118 ' . $disabled . '
119 value=""
120 ' . $name . '
121 />
122 <label
123 ' . $fieldHelpers->getCustomAttributes('cl') . '
124 data-cl
125 for="' . $rowID . '-' . $contentCount . '-chk-' . $optCount . '"
126 class="' . $fieldHelpers->getConversationalCls('cl') . ' ' . $fieldHelpers->getCustomClasses('cl') . '"
127 >
128 <span
129 ' . $fieldHelpers->getCustomAttributes('ck') . '
130 data-bx
131 class="' . $fieldHelpers->getConversationalCls('bx') . ' ' . $fieldHelpers->getConversationalCls('ck') . ' ' . $fieldHelpers->getCustomClasses('ck') . '"
132 >
133 <span class="' . $fieldHelpers->getConversationalCls('opt-key') . '">' . $keyChar . '</span>
134 </span>
135 <span
136 ' . $fieldHelpers->getCustomAttributes('ct') . '
137 class="' . $fieldHelpers->getConversationalCls('ct') . ' ' . $fieldHelpers->getCustomClasses('ct') . '"
138 >
139 ' . $otherOptLbl . '
140 </span>
141 </label>
142 <div data-oinp-wrp class="' . $fieldHelpers->getConversationalCls('other-inp-wrp') . '">
143 <input
144 data-bf-other-inp="' . $rowID . '-chk-' . $optCount . '"
145 type="text"
146 class="' . $fieldHelpers->getConversationalCls('other-inp') . ' ' . $fieldHelpers->getCustomClasses('other-inp') . '"
147 ' . $inpReq . '
148 ' . $inputPh . '
149 />
150 </div>
151 </div>
152 ';
153 }
154
155 return sprintf(
156 '<div' . "\n"
157 . ' %1$s' . "\n"
158 . ' class="%2$s %3$s"' . "\n"
159 . ' role="group" ' . "\n"
160 . ' aria-labelledby="%4$s" ' . "\n"
161 . ' %5$s ' . "\n"
162 . '>' . "\n"
163 . ' <svg class="%6$s" aria-hidden="true">' . "\n"
164 . ' <symbol id="%7$s-ck-svg" viewBox="0 0 12 10">' . "\n"
165 . ' <polyline' . "\n"
166 . ' class="%8$s"' . "\n"
167 . ' points="1.5 6 4.5 9 10.5 1"' . "\n"
168 . ' ></polyline>' . "\n"
169 . ' </symbol>' . "\n"
170 . ' </svg>' . "\n"
171 . ' %9$s' . "\n"
172 . '</div>',
173 $fieldHelpers->getCustomAttributes('cc'),
174 $fieldHelpers->getConversationalCls('cc'),
175 $fieldHelpers->getCustomClasses('cc'),
176 $labelId,
177 $ariaDescribedBy,
178 $fieldHelpers->getConversationalCls('cks'),
179 $rowID,
180 $fieldHelpers->getConversationalCls('ck-svgline'),
181 $checkBoxOptions
182 );
183 }
184 }
185