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

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

203 lines 7.4 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 if (! defined('ABSPATH')) {
6 exit; // Exit if accessed directly.
7 }
8
9 use FluentForm\App\Helpers\Helper;
10 use FluentForm\App\Services\FormBuilder\BaseFieldManager;
11 use FluentForm\Framework\Helpers\ArrayHelper;
12
13 class CustomSubmitButton extends BaseFieldManager
14 {
15 public function __construct()
16 {
17 parent::__construct(
18 'custom_submit_button',
19 'Custom Submit Button',
20 ['submit', 'button', 'custom'],
21 'advanced'
22 );
23 }
24
25 public function pushFormInputType($types)
26 {
27 return $types;
28 }
29
30 public function getComponent()
31 {
32 return [
33 'index' => 12,
34 'element' => $this->key,
35 'attributes' => [
36 'class' => '',
37 'type' => 'submit',
38 ],
39 'settings' => [
40 'button_style' => '',
41 'button_size' => 'md',
42 'align' => 'left',
43 'container_class' => '',
44 'current_state' => 'normal_styles',
45 'background_color' => 'rgb(64, 158, 255)',
46 'color' => 'rgb(255, 255, 255)',
47 'hover_styles' => (object) [
48 'backgroundColor' => '#ffffff',
49 'borderColor' => '#409EFF',
50 'color' => '#409EFF',
51 'borderRadius' => '',
52 'minWidth' => '100%',
53 ],
54 'normal_styles' => (object) [
55 'backgroundColor' => '#409EFF',
56 'borderColor' => '#409EFF',
57 'color' => '#ffffff',
58 'borderRadius' => '',
59 'minWidth' => '100%',
60 ],
61 'button_ui' => (object) [
62 'text' => 'Submit',
63 'type' => 'default',
64 'img_url' => '',
65 ],
66 'conditional_logics' => [],
67 ],
68 'editor_options' => [
69 'title' => $this->title,
70 'icon_class' => 'dashicons dashicons-arrow-right-alt',
71 'template' => 'customButton',
72 ],
73 ];
74 }
75
76 public function pushConditionalSupport($conditonalItems)
77 {
78 return $conditonalItems;
79 }
80
81 public function getGeneralEditorElements()
82 {
83 return [
84 'btn_text',
85 'button_ui',
86 'button_style',
87 'button_size',
88 'align',
89 ];
90 }
91
92 public function getAdvancedEditorElements()
93 {
94 return [
95 'container_class',
96 'class',
97 'conditional_logics',
98 ];
99 }
100
101 public function render($data, $form)
102 {
103 // @todo: We will remove this in our next version [added: 4.0.0]
104 if (class_exists('\FluentFormPro\Components\CustomSubmitField')) {
105 return '';
106 }
107
108 add_filter('fluentform_is_hide_submit_btn_' . $form->id, '__return_true');
109
110 $elementName = $data['element'];
111 $data = apply_filters('fluentform_rendering_field_data_' . $elementName, $data, $form);
112
113 $btnStyle = ArrayHelper::get($data['settings'], 'button_style');
114
115 $btnSize = 'ff-btn-';
116 $btnSize .= isset($data['settings']['button_size']) ? $data['settings']['button_size'] : 'md';
117 $oldBtnType = isset($data['settings']['button_style']) ? '' : ' ff-btn-primary ';
118
119 $align = 'ff-el-group ff-text-' . @$data['settings']['align'];
120
121 $btnClasses = [
122 'ff-btn ff-btn-submit',
123 $oldBtnType,
124 $btnSize,
125 $data['attributes']['class'],
126 ];
127
128 if ('no_style' == $btnStyle) {
129 $btnClasses[] = 'ff_btn_no_style';
130 } else {
131 $btnClasses[] = 'ff_btn_style';
132 }
133
134 $data['attributes']['class'] = trim(implode(' ', array_filter($btnClasses)));
135
136 if ($tabIndex = Helper::getNextTabIndex()) {
137 $data['attributes']['tabindex'] = $tabIndex;
138 }
139
140 $styles = '';
141 if ('' == ArrayHelper::get($data, 'settings.button_style')) {
142 $data['attributes']['class'] .= ' wpf_has_custom_css';
143 // it's a custom button
144 $buttonActiveStyles = ArrayHelper::get($data, 'settings.normal_styles', []);
145 $buttonHoverStyles = ArrayHelper::get($data, 'settings.hover_styles', []);
146
147 $activeStates = '';
148 foreach ($buttonActiveStyles as $styleAtr => $styleValue) {
149 if (! $styleValue) {
150 continue;
151 }
152 if ('borderRadius' == $styleAtr) {
153 $styleValue .= 'px';
154 }
155 $activeStates .= ltrim(strtolower(preg_replace('/[A-Z]([A-Z](?![a-z]))*/', '-$0', $styleAtr)), '_') . ':' . $styleValue . ';';
156 }
157 if ($activeStates) {
158 $styles .= 'form.fluent_form_' . $form->id . ' .wpf_has_custom_css.ff-btn-submit { ' . $activeStates . ' }';
159 }
160 $hoverStates = '';
161 foreach ($buttonHoverStyles as $styleAtr => $styleValue) {
162 if (! $styleValue) {
163 continue;
164 }
165 if ('borderRadius' == $styleAtr) {
166 $styleValue .= 'px';
167 }
168 $hoverStates .= ltrim(strtolower(preg_replace('/[A-Z]([A-Z](?![a-z]))*/', '-$0', $styleAtr)), '-') . ':' . $styleValue . ';';
169 }
170 if ($hoverStates) {
171 $styles .= 'form.fluent_form_' . $form->id . ' .wpf_has_custom_css.ff-btn-submit:hover { ' . $hoverStates . ' } ';
172 }
173 } elseif ('no_style' != $btnStyle) {
174 $styles .= 'form.fluent_form_' . $form->id . ' .ff-btn-submit { background-color: ' . esc_attr(ArrayHelper::get($data, 'settings.background_color')) . '; color: ' . esc_attr(ArrayHelper::get($data, 'settings.color')) . '; }';
175 }
176
177 $atts = $this->buildAttributes($data['attributes']);
178 $hasConditions = $this->hasConditions($data) ? 'has-conditions ' : '';
179 $cls = trim($align . ' ' . $data['settings']['container_class'] . ' ' . $hasConditions);
180
181 $html = "<div class='" . esc_attr($cls) . " ff_submit_btn_wrapper ff_submit_btn_wrapper_custom'>";
182
183 // ADDED IN v1.2.6 - updated in 1.4.4
184 if (isset($data['settings']['button_ui'])) {
185 if ('default' == $data['settings']['button_ui']['type']) {
186 $html .= '<button ' . $atts . '>' . fluentform_sanitize_html($data['settings']['button_ui']['text'], false) . '</button>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- $atts is escaped before being passed in.
187 } else {
188 $html .= "<button class='ff-btn-submit' type='submit'><img style='max-width: 200px;' src='" . esc_url($data['settings']['button_ui']['img_url']) . "' alt='Submit Form'></button>";
189 }
190 } else {
191 $html .= '<button ' . $atts . '>' . fluentform_sanitize_html($data['settings']['btn_text'], false) . '</button>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- $atts is escaped before being passed in.
192 }
193
194 if ($styles) {
195 $html .= '<style>' . $styles . '</style>';
196 }
197
198 $html .= '</div>';
199
200 $this->printContent('fluentform_rendering_field_html_' . $elementName, $html, $data, $form);
201 }
202 }
203