PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 2.9.1
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v2.9.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 / Theme / Fields / ImageSelectField.php

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

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