PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 4.3.18
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v4.3.18
6.2.14 6.2.13 6.2.12 6.2.10 6.2.11 6.2.9 6.2.8 6.2.7 6.2.6 6.2.5 6.2.4 6.2.3 6.2.2 3.6.22 3.6.31 3.6.40 3.6.41 3.6.42 3.6.50 3.6.51 3.6.60 3.6.61 3.6.62 3.6.64 3.6.65 All 196 releases
fluentform / app / Services / FormBuilder / Components / Text.php

Text.php in Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder 4.3.18, at app/Services/FormBuilder/Components/Text.php

148 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 FluentForm\App\Services\FormBuilder\Components;
4
5 use FluentForm\App\Helpers\Helper;
6 use FluentForm\Framework\Helpers\ArrayHelper;
7
8 class Text extends BaseComponent
9 {
10 /**
11 * Compile and echo the html element
12 *
13 * @param array $data [element data]
14 * @param \stdClass $form [Form Object]
15 *
16 * @return void
17 */
18 public function compile($data, $form)
19 {
20 $elementName = $data['element'];
21 $data = apply_filters('fluentform_rendering_field_data_' . $elementName, $data, $form);
22
23 // </mask input>
24 if (isset($data['settings']['temp_mask']) && 'custom' != $data['settings']['temp_mask']) {
25 $data['attributes']['data-mask'] = $data['settings']['temp_mask'];
26 }
27
28 if ('custom' == ArrayHelper::get($data, 'settings.temp_mask')) {
29 if ('yes' == ArrayHelper::get($data, 'settings.data-mask-reverse')) {
30 $data['attributes']['data-mask-reverse'] = 'true';
31 }
32
33 if ('yes' == ArrayHelper::get($data, 'settings.data-clear-if-not-match')) {
34 $data['attributes']['data-clear-if-not-match'] = 'true';
35 }
36 }
37
38 if (isset($data['attributes']['data-mask'])) {
39 wp_enqueue_script(
40 'jquery-mask',
41 $this->app->publicUrl('libs/jquery.mask.min.js'),
42 ['jquery'],
43 false,
44 true
45 );
46 }
47
48 if ('input_number' == $data['element'] || 'custom_payment_component' == $data['element']) {
49 if (
50 ArrayHelper::get($data, 'settings.calculation_settings.status') &&
51 $formula = ArrayHelper::get($data, 'settings.calculation_settings.formula')
52 ) {
53 $data['attributes']['data-calculation_formula'] = $formula;
54 $data['attributes']['class'] .= ' ff_has_formula';
55 $data['attributes']['readonly'] = true;
56 $data['attributes']['type'] = 'text';
57
58 add_filter('fluentform_form_class', function ($css_class, $targetForm) use ($form) {
59 if ($targetForm->id == $form->id) {
60 $css_class .= ' ff_calc_form';
61 }
62 return $css_class;
63 }, 10, 2);
64 do_action('ff_rendering_calculation_form', $form, $data);
65 } else {
66 if (! apply_filters('fluentform_disable_inputmode', false)) {
67 $inputMode = ArrayHelper::get($data, 'attributes.inputmode');
68 if (! $inputMode) {
69 $inputMode = 'numeric';
70 }
71 $data['attributes']['inputmode'] = $inputMode;
72 }
73 }
74
75 if ($step = ArrayHelper::get($data, 'settings.number_step')) {
76 $data['attributes']['step'] = $step;
77 } elseif ('number' == ArrayHelper::get($data, 'attributes.type')) {
78 $data['attributes']['step'] = 'any';
79 }
80
81 $min = ArrayHelper::get($data, 'settings.validation_rules.min.value');
82 if ($min || 0 == $min) {
83 $data['attributes']['min'] = $min;
84 }
85
86 if ($max = ArrayHelper::get($data, 'settings.validation_rules.max.value')) {
87 $data['attributes']['max'] = $max;
88 }
89
90 if ($formatter = ArrayHelper::get($data, 'settings.numeric_formatter')) {
91 $formatters = Helper::getNumericFormatters();
92 if (! empty($formatters[$formatter]['settings'])) {
93 $data['attributes']['class'] .= ' ff_numeric';
94 $data['attributes']['data-formatter'] = json_encode($formatters[$formatter]['settings']);
95 wp_enqueue_script(
96 'currency',
97 $this->app->publicUrl('libs/currency.min.js'),
98 [],
99 '2.0.3',
100 true
101 );
102 $data['attributes']['type'] = 'text';
103 }
104 }
105 }
106
107 // For hidden input
108 if ('hidden' == $data['attributes']['type']) {
109 $attributes = $this->buildAttributes($data['attributes'], $form);
110 echo '<input ' . $attributes . '>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- $attributes is escaped before being passed in.
111 return;
112 }
113
114 if ($tabIndex = Helper::getNextTabIndex()) {
115 $data['attributes']['tabindex'] = $tabIndex;
116 }
117
118 $data['attributes']['class'] = @trim('ff-el-form-control ' . $data['attributes']['class']);
119 $data['attributes']['id'] = $this->makeElementId($data, $form);
120
121 $elMarkup = $this->buildInputGroup($data, $form);
122
123 $html = $this->buildElementMarkup($elMarkup, $data, $form);
124
125 $this->printContent('fluentform_rendering_field_html_' . $elementName, $html, $data, $form);
126 }
127
128 private function buildInputGroup($data, $form)
129 {
130 $input = '<input ' . $this->buildAttributes($data['attributes'], $form) . '>';
131 $prefix = ArrayHelper::get($data, 'settings.prefix_label');
132 $suffix = ArrayHelper::get($data, 'settings.suffix_label');
133 if ($prefix || $suffix) {
134 $wrapper = '<div class="ff_input-group">';
135 if ($prefix) {
136 $wrapper .= '<div class="ff_input-group-prepend"><span class="ff_input-group-text">' . fluentform_sanitize_html($prefix, false) . '</span></div>';
137 }
138 $wrapper .= $input;
139 if ($suffix) {
140 $wrapper .= '<div class="ff_input-group-append"><span class="ff_input-group-text">' . fluentform_sanitize_html($suffix, false) . '</span></div>';
141 }
142 $wrapper .= '</div>';
143 return $wrapper;
144 }
145 return $input;
146 }
147 }
148