PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 3.3.1
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v3.3.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 / ImageSelectField.php

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

161 lines 5.8 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 ImageSelectField
8 {
9 public static function init($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error = null, $value = null)
10 {
11 $inputWrapper = new ConversationalInputWrapper($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error, $value);
12 $input = self::field($field, $rowID, $form_atomic_Cls_map, $formID, $value);
13 return $inputWrapper->wrapper($input);
14 }
15
16 private static function field($field, $rowID, $form_atomic_Cls_map, $formID, $value)
17 {
18 $fieldHelpers = new ConversationalFieldHelpers($formID, $field, $rowID, $form_atomic_Cls_map);
19
20 $name = $fieldHelpers->name();
21 $req = $fieldHelpers->required();
22 $ariaDescribedBy = $fieldHelpers->ariaDescribedBy();
23 $ariaRequired = $fieldHelpers->ariaRequired();
24 $labelId = $fieldHelpers->getLabelId();
25
26 $bfFrontendFormIds = FrontendHelpers::$bfFrontendFormIds;
27 $contentCount = count($bfFrontendFormIds);
28
29 $imageOption = '';
30 if (!empty($field->val)) {
31 $value = $field->val;
32 }
33 if (!empty($value) && false !== strpos($value, BITFORMS_BF_SEPARATOR)) {
34 $defaultValues = explode(BITFORMS_BF_SEPARATOR, $value);
35 } else {
36 $defaultValues = isset($value) ? explode(',', $value) : [];
37 }
38
39 if (isset($field->opt)) {
40 $checkedImg = $field->tickImgSrc;
41 foreach ($field->opt as $key => $opt) {
42 $val = isset($opt->val) ? $opt->val : $opt->lbl;
43 $img = $opt->img;
44 $lbl = $fieldHelpers->renderHTMR($opt->lbl);
45 $checked = '';
46 $inpType = $field->inpType;
47 $imgAlt = $fieldHelpers->esc_html($lbl);
48 $disabled = '';
49
50 if ($fieldHelpers->property_exists_nested($opt, 'check', true)) {
51 $checked = 'checked';
52 } elseif (in_array($val, $defaultValues)) {
53 $checked = 'checked';
54 }
55
56 if (isset($field->mx) && !empty($field->valid->disableOnMax) && !$checked && ((int) $field->mx <= count($defaultValues))) {
57 $disabled = 'disabled';
58 }
59
60 $optLblHide = null;
61
62 if (!$field->optLblHide) {
63 $optLblHide = sprintf(
64 '<div
65 class="%1$s"
66 %2$s
67 >
68 <span
69 class="%3$s"
70 %4$s
71 >
72 %5$s
73 </span>
74 </div>',
75 $fieldHelpers->getConversationalCls('tc') . ' ' . $fieldHelpers->getCustomClasses('tc'),
76 $fieldHelpers->getCustomAttributes('tc'),
77 $fieldHelpers->getConversationalCls('img-title') . ' ' . $fieldHelpers->getCustomClasses('img-title'),
78 $fieldHelpers->getCustomAttributes('img-title'),
79 $fieldHelpers->kses_post($lbl)
80 );
81 } else {
82 $optLblHide = '';
83 }
84
85 $imageOption .= '<div
86 class="' . $fieldHelpers->getConversationalCls('inp-opt') . ' ' . $fieldHelpers->getCustomClasses('inp-opt') . '"
87 ' . $fieldHelpers->getCustomAttributes('inp-opt') . '
88 >
89 <input
90 class="' . $fieldHelpers->getConversationalCls('img-inp') . ' ' . $fieldHelpers->getCustomClasses('img-inp') . '"
91 type="' . $inpType . '"
92 id="' . $rowID . '-' . $contentCount . '-img-wrp-' . $key . '"
93 ' . $name . '
94 value="' . $fieldHelpers->esc_attr($val) . '"
95 ' . $checked . '
96 ' . $req . '
97 ' . $disabled . '
98 ' . $fieldHelpers->getCustomAttributes('img-inp') . '
99 />
100 <label
101 for="' . $rowID . '-' . $contentCount . '-img-wrp-' . $key . '"
102 class="' . $fieldHelpers->getConversationalCls('img-wrp') . ' ' . $fieldHelpers->getCustomClasses('img-wrp') . '"
103 ' . $fieldHelpers->getCustomAttributes('img-wrp') . '
104 >
105 <span
106 class="' . $fieldHelpers->getConversationalCls('check-box') . ' ' . $fieldHelpers->getCustomClasses('check-box') . '"
107 ' . $fieldHelpers->getCustomAttributes('check-box') . '
108 >
109 <img
110 src="' . $checkedImg . '"
111 alt=""
112 class="' . $fieldHelpers->getConversationalCls('check-img') . ' ' . $fieldHelpers->getCustomClasses('check-img') . '"
113 ' . $fieldHelpers->getCustomAttributes('check-img') . '
114 />
115 </span>
116
117 <span
118 class="' . $fieldHelpers->getConversationalCls('img-card-wrp') . ' ' . $fieldHelpers->getCustomClasses('img-card-wrp') . '"
119 ' . $fieldHelpers->getCustomAttributes('img-card-wrp') . '
120 >
121 <img
122 src="' . $img . '"
123 alt="' . $imgAlt . '"
124 aria-label="' . $imgAlt . '"
125 class="' . $fieldHelpers->getConversationalCls('select-img') . ' ' . $fieldHelpers->getCustomClasses('select-img') . '"
126 ' . $fieldHelpers->getCustomAttributes('select-img') . '
127 />
128 ' . $optLblHide . '
129 </span>
130 </label>
131 </div>
132 ';
133 }
134 }
135
136 return sprintf(
137 '<div
138 class="%1$s"
139 %2$s
140 >
141 <div
142 class="%3$s"
143 %4$s
144 role="group"
145 aria-labelledby="%5$s"
146 %6$s
147 >
148 %7$s
149 </div>
150 </div>',
151 $fieldHelpers->getConversationalCls('inp-fld-wrp') . ' ' . $fieldHelpers->getCustomClasses('inp-fld-wrp'),
152 $fieldHelpers->getCustomAttributes('inp-fld-wrp'),
153 $fieldHelpers->getConversationalCls('ic') . ' ' . $fieldHelpers->getCustomClasses('ic'),
154 $fieldHelpers->getCustomAttributes('ic'),
155 $labelId,
156 $ariaDescribedBy,
157 $imageOption
158 );
159 }
160 }
161