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 / RatingField.php

RatingField.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/RatingField.php

122 lines 3.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\Theme\Fields;
4
5 use BitCode\BitForm\Core\Util\FrontendHelpers;
6
7 class RatingField
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 $ratingOption = '';
27
28 $checkedIndex = '';
29
30 if (isset($field->opt)) {
31 $defaultValue = isset($field->val) ? $field->val : '';
32 foreach ($field->opt as $key => $opt) {
33 if ($defaultValue && $defaultValue === $opt->val) {
34 $checkedIndex = $key;
35 } elseif (isset($opt->check) && true === $opt->check) {
36 $checkedIndex = $key;
37 }
38 }
39
40 $checkedCls = null;
41
42 foreach ($field->opt as $key => $opt) {
43 $val = $opt->val;
44 $img = $opt->img;
45 $lbl = $opt->lbl;
46 $checked = '';
47
48 // if ($defaultValue && $opt->val === $defaultValue) {
49 // $checked = "checked='checked'";
50 // } elseif (isset($opt->check) && true === $opt->check) {
51 // $checked = "checked='{$opt->check}'";
52 // } else {
53 // $checked = '';
54 // }
55
56 if ($defaultValue ) {
57 if ($opt->val === $defaultValue)
58 $checked = "checked='1'";
59 } else {
60 if (isset($opt->check) && true === $opt->check) {
61 $checked = "checked='{$opt->check}'";
62 } else {
63 $checked = '';
64 }
65 }
66
67 if (!empty($checkedIndex) && $key <= $checkedIndex) {
68 $checkedCls = $rowID . '-rating-selected';
69 } else {
70 $checkedCls = null;
71 }
72 $ratingOption .= <<<RATINGOPTION
73 <label
74 class="{$fieldHelpers->getAtomicCls('rating-lbl')} {$fieldHelpers->getCustomClasses('rating-lbl')}"
75 for="{$rowID}-{$contentCount}-rating-{$key}"
76 {$fieldHelpers->getCustomAttributes('rating-lbl')}
77 data-indx="{$key}"
78 >
79 <input
80 type="radio"
81 class="{$fieldHelpers->getAtomicCls('rating-input')} {$fieldHelpers->getCustomClasses('rating-input')}"
82 {$name}
83 value={$val}
84 aria-label="{$lbl}"
85 id="{$rowID}-{$contentCount}-rating-{$key}"
86 {$checked}
87 {$req}
88 {$fieldHelpers->getCustomAttributes('rating-input')}
89 />
90 <img
91 class="{$fieldHelpers->getAtomicCls('rating-img')} {$fieldHelpers->getCustomClasses('rating-img')} {$checkedCls}"
92 src="{$img}"
93 alt="{$lbl}"
94 aria-label="{$lbl}"
95 {$fieldHelpers->getCustomAttributes('rating-img')}
96 />
97 </label>
98 RATINGOPTION;
99 }
100 }
101
102 return <<<RATINGFIELD
103 <div
104 {$fieldHelpers->getCustomAttributes('inp-fld-wrp')}
105 class="{$fieldHelpers->getAtomicCls('inp-fld-wrp')} {$fieldHelpers->getCustomClasses('inp-fld-wrp')}"
106 >
107 <div
108 {$fieldHelpers->getCustomAttributes('rating-wrp')}
109 class="{$fieldHelpers->getAtomicCls('rating-wrp')} {$fieldHelpers->getCustomClasses('rating-wrp')}"
110 tabindex="0"
111 >
112 {$ratingOption}
113 </div>
114 <span
115 class="{$fieldHelpers->getAtomicCls('rating-msg')} {$fieldHelpers->getCustomClasses('rating-msg')}"
116 {$fieldHelpers->getCustomAttributes('rating-msg')}
117 >
118 </span>
119 </div>
120 RATINGFIELD;
121 }
122 }