PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 6.2.14
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v6.2.14
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 / SubmitButton.php

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

175 lines 7.7 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 defined('ABSPATH') or die;
6
7 use FluentForm\App\Helpers\Helper;
8 use FluentForm\Framework\Helpers\ArrayHelper;
9
10 class SubmitButton extends BaseComponent
11 {
12 /**
13 * Compile and echo the html element
14 *
15 * @param array $data [element data]
16 * @param \stdClass $form [Form Object]
17 *
18 * @return void
19 */
20 public function compile($data, $form)
21 {
22 $maybeHide = apply_filters_deprecated(
23 'fluentform_is_hide_submit_btn_' . $form->id,
24 [
25 false
26 ],
27 FLUENTFORM_FRAMEWORK_UPGRADE,
28 'fluentform/is_hide_submit_btn_' . $form->id,
29 'Use fluentform/is_hide_submit_btn_' . $form->id. ' instead of fluentform_is_hide_submit_btn_' . $form->id
30 );
31 if (apply_filters('fluentform/is_hide_submit_btn_' . $form->id, $maybeHide)) {
32 return '';
33 }
34
35 $elementName = $data['element'];
36
37 $data = apply_filters_deprecated(
38 'fluentform_rendering_field_data_' . $elementName,
39 [
40 $data,
41 $form
42 ],
43 FLUENTFORM_FRAMEWORK_UPGRADE,
44 'fluentform/rendering_field_data_' . $elementName,
45 'Use fluentform/rendering_field_data_' . $elementName . ' instead of fluentform_rendering_field_data_' . $elementName
46 );
47
48 $data = apply_filters('fluentform/rendering_field_data_' . $elementName, $data, $form);
49
50 $btnStyle = ArrayHelper::get($data['settings'], 'button_style');
51
52 /* This filter is deprecated and will be removed soon */
53 $noStyle = apply_filters('fluentform_submit_button_force_no_style', false);
54
55 if (apply_filters('fluentform/submit_button_force_no_style', $noStyle)) {
56 $btnStyle = 'no_style';
57 }
58
59 $btnSize = 'ff-btn-';
60 $btnSize .= isset($data['settings']['button_size']) ? $data['settings']['button_size'] : 'md';
61 $oldBtnType = isset($data['settings']['button_style']) ? '' : ' ff-btn-primary ';
62
63 $btnClasses = [
64 'ff-btn ff-btn-submit',
65 $oldBtnType,
66 $btnSize,
67 $data['attributes']['class'],
68 ];
69
70 $loadDefaultFluentStyle = $form->theme != 'ffs_inherit_theme';
71 if(!$loadDefaultFluentStyle){
72 $btnStyle = 'no_style';
73 }
74 if ('no_style' == $btnStyle) {
75 $btnClasses[] = 'ff_btn_no_style';
76 } else {
77 $btnClasses[] = 'ff_btn_style';
78 }
79
80 $align = 'ff-el-group ff-text-' . @$data['settings']['align'];
81 $data['attributes']['class'] = trim(implode(' ', array_filter($btnClasses)));
82
83 if ($tabIndex = Helper::getNextTabIndex()) {
84 $data['attributes']['tabindex'] = $tabIndex;
85 }
86
87 $styles = '';
88 if ('' == ArrayHelper::get($data, 'settings.button_style')) {
89 $data['attributes']['class'] .= ' wpf_has_custom_css';
90 // it's a custom button
91 $buttonActiveStyles = ArrayHelper::get($data, 'settings.normal_styles', []);
92 $buttonHoverStyles = ArrayHelper::get($data, 'settings.hover_styles', []);
93
94 $activeStates = '';
95 foreach ($buttonActiveStyles as $styleAtr => $styleValue) {
96 if ('0' !== $styleValue && !$styleValue) {
97 continue;
98 }
99 if ('borderRadius' == $styleAtr) {
100 $styleValue .= 'px';
101 }
102 $activeStates .= ltrim(strtolower(preg_replace('/[A-Z]([A-Z](?![a-z]))*/', '-$0', $styleAtr)), '_') . ':' . $styleValue . ';';
103 }
104 if ($activeStates) {
105 $styles .= 'form.fluent_form_' . $form->id . ' .wpf_has_custom_css.ff-btn-submit { ' . $activeStates . ' }';
106 }
107 $hoverStates = '';
108 foreach ($buttonHoverStyles as $styleAtr => $styleValue) {
109 if ('0' !== $styleValue && !$styleValue) {
110 continue;
111 }
112 if ('borderRadius' == $styleAtr) {
113 $styleValue .= 'px';
114 }
115 $hoverStates .= ltrim(strtolower(preg_replace('/[A-Z]([A-Z](?![a-z]))*/', '-$0', $styleAtr)), '-') . ':' . $styleValue . ';';
116 }
117 if ($hoverStates) {
118 $styles .= 'form.fluent_form_' . $form->id . ' .wpf_has_custom_css.ff-btn-submit:hover { ' . $hoverStates . ' } ';
119 }
120 } elseif ('no_style' != $btnStyle) {
121 $bgColor = esc_attr(ArrayHelper::get($data, 'settings.background_color'));
122 $bgColor = str_replace('#1a7efb','var(--fluentform-primary)',$bgColor);
123 $styles .= 'form.fluent_form_' . $form->id . ' .ff-btn-submit:not(.ff_btn_no_style) { background-color: ' . $bgColor . '; color: ' . esc_attr(ArrayHelper::get($data, 'settings.color')) . '; }';
124 }
125
126 $atts = $this->buildAttributes($data['attributes']);
127 $cls = trim($align . ' ' . $data['settings']['container_class']);
128
129 $html = "<div class='" . esc_attr($cls) . " ff_submit_btn_wrapper'>";
130
131 // ADDED IN v1.2.6 - updated in 1.4.4
132 if (isset($data['settings']['button_ui'])) {
133 if ('default' == $data['settings']['button_ui']['type']) {
134 $buttonText = $data['settings']['button_ui']['text'];
135 $html .= '<button ' . $atts . ' aria-label="' . esc_attr($this->removeShortcode($buttonText)) . '">' . fluentform_sanitize_html($buttonText) . '</button>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- $atts is escaped before being passed in.
136 } else {
137 $html .= "<button class='ff-btn-submit' type='submit' aria-label='Submit The Form'><img style='max-width: 200px;' src='" . esc_url($data['settings']['button_ui']['img_url']) . "' alt='Submit Form'></button>";
138 }
139 } else {
140 $buttonText = $data['settings']['btn_text'];
141 $html .= '<button ' . $atts . ' aria-label="' . esc_attr($this->removeShortcode($buttonText)) . '">' . fluentform_sanitize_html($buttonText) . '</button>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- $atts is escaped before being passed in.
142 }
143
144 // SECURITY (FINDING-12): the custom-button style map keys and values are user-controlled
145 // and unsanitized at save; a value like "#fff}</style><script>..." would break out of the
146 // <style> element. fluentformSanitizeCSS() blanks any CSS containing a tag pattern.
147 $styles = fluentformSanitizeCSS($styles);
148 if ($styles) {
149 if (did_action('wp_footer') || Helper::isBlockEditor()) {
150 $html .= '<style>' . $styles . '</style>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- $styles is sanitized via fluentformSanitizeCSS().
151 } else {
152 add_action('wp_footer', function () use ($styles) {
153 echo '<style>' . $styles . '</style>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- $styles is sanitized via fluentformSanitizeCSS().
154 });
155 }
156 }
157
158 $html .= '</div>';
159
160 $html = apply_filters_deprecated(
161 'fluentform_rendering_field_html_' . $elementName,
162 [
163 $html,
164 $data,
165 $form
166 ],
167 FLUENTFORM_FRAMEWORK_UPGRADE,
168 'fluentform/rendering_field_html_' . $elementName,
169 'Use fluentform/rendering_field_html_' . $elementName . ' instead of fluentform_rendering_field_html_' . $elementName
170 );
171
172 $this->printContent('fluentform/rendering_field_html_' . $elementName, $html, $data, $form);
173 }
174 }
175