PluginProbe
UiCore Elements – Free widgets and templates for Elementor / 1.3.18
UiCore Elements – Free widgets and templates for Elementor v1.3.18
1.3.18 1.3.17 1.3.16 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.2.0 1.2.1 1.2.2 1.2.3 All 42 releases
← All changes | includes/widgets/contact-form.php +1125 -2184 1.0.7 → 1.3.18 View file →
@@ -1,10 +1,13 @@
1 1 <?php
2 +
2 3 namespace UiCoreElements;
3 4
4 5 use UiCoreElements\Helper;
5 6 use UiCoreElements\Utils\Contact_Form_Service;
6 7 use UiCoreElements\Utils\Form_Component;
8 +use UiCoreElements\Utils\Newsletter_Services;
9 +
7 10 use Elementor\Controls_Manager;
8 11 use Elementor\Icons_Manager;
9 12 use Elementor\Utils;
10 13 use Elementor\Repeater;
@@ -22,30 +25,35 @@
22 25 * @author Lucas Marini Falbo <[email protected]>
23 26 * @since 1.0.5
24 27 */
25 28
26 -class ContactForm extends UiCoreWidget {
29 +class ContactForm extends UiCoreWidget
30 +{
27 31
28 32 use Form_Component;
29 33
30 - public function get_name() {
31 - return 'uicore-contact-form';
32 - }
34 + public function get_name()
35 + {
36 + return 'uicore-contact-form';
37 + }
33 38
34 - public function get_title() {
35 - return __( 'Contact Form', 'uicore-elements' );
36 - }
39 + public function get_title()
40 + {
41 + return __('Contact Form', 'uicore-elements');
42 + }
37 43
38 - public function get_icon() {
39 - return 'eicon-form-horizontal ui-e-widget';
40 - }
44 + public function get_icon()
45 + {
46 + return 'eicon-form-horizontal ui-e-widget';
47 + }
41 48 public function get_categories()
42 49 {
43 50 return ['uicore'];
44 51 }
45 - public function get_keywords() {
46 - return [ 'form', 'forms', 'contact', 'mail', 'send', 'field', 'button', 'recaptcha', ];
47 - }
52 + public function get_keywords()
53 + {
54 + return ['form', 'forms', 'contact', 'mail', 'send', 'field', 'button', 'recaptcha',];
55 + }
48 56 public function get_styles()
49 57 {
50 58 return ['contact-form'];
51 59 }
@@ -60,21 +68,26 @@
60 68 'custom_condition' => $this->check_recaptcha_version('v3')
61 69 ],
62 70 'repeater-custom-key' => [
63 71 'custom_condition' => $this->is_edit_mode()
64 - ]
72 + ]
65 73 ];
66 74 }
75 + public function has_widget_inner_wrapper(): bool
76 + {
77 + // TODO: remove after Optmized Markup experiment is merged to the core
78 + return ! \Elementor\Plugin::$instance->experiments->is_feature_active('e_optimized_markup');;
79 + }
67 80 function check_recaptcha_version($version)
68 81 {
69 82
70 - if($this->is_edit_mode()){
83 + if ($this->is_edit_mode()) {
71 84 return true;
72 85 }
73 86 $settings = $this->get_settings_for_display();
74 87 foreach ($settings['form_fields'] as $field) {
75 88 $version_to_check = $version === 'v2' ? 'recaptcha' : 'recaptcha_v3';
76 - if($field['field_type'] === $version_to_check){
89 + if ($field['field_type'] === $version_to_check) {
77 90 return true;
78 91 }
79 92 }
80 93 return false;
@@ -79,854 +92,696 @@
79 92 }
80 93 return false;
81 94 }
82 95
83 - // Helper Functions
84 - function get_field_types()
96 + // Helper Functions
97 + function get_field_types()
85 98 {
86 99 return [
87 - 'text' => esc_html__( 'Text', 'uicore-elements' ),
88 - 'email' => esc_html__( 'Email', 'uicore-elements' ),
89 - 'textarea' => esc_html__( 'Textarea', 'uicore-elements' ),
90 - 'url' => esc_html__( 'URL', 'uicore-elements' ),
91 - 'tel' => esc_html__( 'Tel', 'uicore-elements' ),
92 - 'radio' => esc_html__( 'Radio', 'uicore-elements' ),
93 - 'select' => esc_html__( 'Select', 'uicore-elements' ),
94 - 'checkbox' => esc_html__( 'Checkbox', 'uicore-elements' ),
95 - 'acceptance' => esc_html__( 'Acceptance', 'uicore-elements' ),
96 - 'number' => esc_html__( 'Number', 'uicore-elements' ),
97 - 'date' => esc_html__( 'Date', 'uicore-elements' ),
98 - 'time' => esc_html__( 'Time', 'uicore-elements' ),
99 - 'file' => esc_html__( 'File Upload', 'uicore-elements' ),
100 - 'password' => esc_html__( 'Password', 'uicore-elements' ),
101 - 'address' => esc_html__( 'Honeypot', 'uicore-elements' ),
102 - 'recaptcha' => esc_html__( 'reCAPTCHA', 'uicore-elements' ),
103 - 'recaptcha_v3' => esc_html__( 'reCAPTCHA V3', 'uicore-elements' ),
104 - 'html' => esc_html__( 'HTML', 'uicore-elements' ),
105 - 'hidden' => esc_html__( 'Hidden', 'uicore-elements' ),
106 - ];
100 + 'text' => esc_html__('Text', 'uicore-elements'),
101 + 'email' => esc_html__('Email', 'uicore-elements'),
102 + 'textarea' => esc_html__('Textarea', 'uicore-elements'),
103 + 'url' => esc_html__('URL', 'uicore-elements'),
104 + 'tel' => esc_html__('Tel', 'uicore-elements'),
105 + 'radio' => esc_html__('Radio', 'uicore-elements'),
106 + 'select' => esc_html__('Select', 'uicore-elements'),
107 + 'checkbox' => esc_html__('Checkbox', 'uicore-elements'),
108 + 'acceptance' => esc_html__('Acceptance', 'uicore-elements'),
109 + 'number' => esc_html__('Number', 'uicore-elements'),
110 + 'date' => esc_html__('Date', 'uicore-elements'),
111 + 'time' => esc_html__('Time', 'uicore-elements'),
112 + 'file' => esc_html__('File Upload', 'uicore-elements'),
113 + 'password' => esc_html__('Password', 'uicore-elements'),
114 + 'address' => esc_html__('Honeypot', 'uicore-elements'),
115 + 'recaptcha' => esc_html__('reCAPTCHA', 'uicore-elements'),
116 + 'recaptcha_v3' => esc_html__('reCAPTCHA V3', 'uicore-elements'),
117 + 'html' => esc_html__('HTML', 'uicore-elements'),
118 + 'hidden' => esc_html__('Hidden', 'uicore-elements'),
119 + ];
107 120 }
108 121
109 - function get_attribute_name( $item ) {
110 - return "form_fields[{$item['custom_id']}]";
111 - }
112 - function get_attribute_id( $item ) {
113 - return 'form-field-' . $item['custom_id'];
114 - }
115 - function add_required_attribute( $element ) {
116 - $this->add_render_attribute( $element, 'required', 'required' );
117 - $this->add_render_attribute( $element, 'aria-required', 'true' );
118 - }
122 + function get_attribute_name($item)
123 + {
124 + return "form_fields[{$item['custom_id']}]";
125 + }
126 + function get_attribute_id($item)
127 + {
128 + return 'form-field-' . $item['custom_id'];
129 + }
130 + function add_required_attribute($element, $js_verication = false)
131 + {
119 132
120 - // Control Render Functions
121 - function register_submit_email_controls($instance, $slug = '') {
122 - $instance->add_control(
123 - 'email_to' . $slug,
124 - [
125 - 'label' => esc_html__( 'To', 'uicore-elements' ),
126 - 'type' => Controls_Manager::TEXT,
127 - 'default' => get_option( 'admin_email' ),
128 - 'ai' => [
129 - 'active' => false,
130 - ],
131 - 'placeholder' => get_option( 'admin_email' ),
132 - 'label_block' => true,
133 - 'title' => esc_html__( 'Separate emails with commas', 'uicore-elements' ),
134 - 'render_type' => 'none',
135 - 'dynamic' => [
136 - 'active' => true,
137 - ],
138 - ]
139 - );
133 + // Used for elements (eg: checkbox) that aren't natively supported by the browsers validations
134 + if ($js_verication) {
135 + $this->add_render_attribute($element, 'data-ui-e-required', 'true');
136 + return;
137 + }
140 138
141 - /* translators: %s: Site title. */
142 - $default_message = sprintf( html_entity_decode( esc_html__( 'New message from "%s"', 'uicore-elements' ) ), get_option( 'blogname' ) );
139 + // Default method
140 + $this->add_render_attribute($element, 'required', 'required');
141 + $this->add_render_attribute($element, 'aria-required', 'true');
142 + }
143 143
144 - $instance->add_control(
145 - 'email_subject' . $slug,
146 - [
147 - 'label' => esc_html__( 'Subject', 'uicore-elements' ),
148 - 'type' => Controls_Manager::TEXT,
149 - 'default' => $default_message,
150 - 'ai' => [
151 - 'active' => false,
152 - ],
153 - 'placeholder' => $default_message,
154 - 'label_block' => true,
155 - 'render_type' => 'none',
156 - 'dynamic' => [
157 - 'active' => true,
158 - ],
159 - ]
160 - );
161 -
162 - $instance->add_control(
163 - 'email_content' . $slug,
164 - [
165 - 'label' => esc_html__( 'Message', 'uicore-elements' ),
166 - 'type' => Controls_Manager::TEXTAREA,
167 - 'default' => '[all-fields]',
168 - 'ai' => [
169 - 'active' => false,
170 - ],
171 - 'placeholder' => '[all-fields]',
172 - 'description' => sprintf(
173 - /* translators: %s: The [all-fields] shortcode. */
174 - esc_html__( 'By default, all form fields are sent via %s shortcode. To customize sent fields, copy the shortcode that appears inside each field and paste it above.', 'uicore-elements' ),
175 - '<code>[all-fields]</code>'
176 - ),
177 - 'render_type' => 'none',
178 - 'dynamic' => [
179 - 'active' => true,
180 - ],
181 - ]
182 - );
183 -
184 - $site_domain = Helper::get_site_domain();
185 -
186 - $instance->add_control(
187 - 'email_from' . $slug,
188 - [
189 - 'label' => esc_html__( 'From Email', 'uicore-elements' ),
190 - 'type' => Controls_Manager::TEXT,
191 - 'default' => 'email@' . $site_domain,
192 - 'ai' => [
193 - 'active' => false,
194 - ],
195 - 'render_type' => 'none',
196 - 'dynamic' => [
197 - 'active' => true,
198 - ],
199 - ]
200 - );
201 -
202 - $instance->add_control(
203 - 'email_from_name' . $slug,
204 - [
205 - 'label' => esc_html__( 'From Name', 'uicore-elements' ),
206 - 'type' => Controls_Manager::TEXT,
207 - 'default' => get_bloginfo( 'name' ),
208 - 'ai' => [
209 - 'active' => false,
210 - ],
211 - 'render_type' => 'none',
212 - 'dynamic' => [
213 - 'active' => true,
214 - ],
215 - ]
216 - );
217 -
218 - $instance->add_control(
219 - 'email_reply_to' . $slug,
220 - [
221 - 'label' => esc_html__( 'Reply-To', 'uicore-elements' ),
222 - 'type' => Controls_Manager::TEXT,
223 - 'options' => [
224 - '' => '',
225 - ],
226 - 'default' => 'noreply@' . Helper::get_site_domain(),
227 - 'render_type' => 'none',
228 - ]
229 - );
230 -
231 - $instance->add_control(
232 - 'email_to_cc' . $slug,
233 - [
234 - 'label' => esc_html__( 'Cc', 'uicore-elements' ),
235 - 'type' => Controls_Manager::TEXT,
236 - 'default' => '',
237 - 'ai' => [
238 - 'active' => false,
239 - ],
240 - 'title' => esc_html__( 'Separate emails with commas', 'uicore-elements' ),
241 - 'render_type' => 'none',
242 - 'dynamic' => [
243 - 'active' => true,
244 - ],
245 - ]
246 - );
247 -
248 - $instance->add_control(
249 - 'email_to_bcc' . $slug,
250 - [
251 - 'label' => esc_html__( 'Bcc', 'uicore-elements' ),
252 - 'type' => Controls_Manager::TEXT,
253 - 'default' => '',
254 - 'ai' => [
255 - 'active' => false,
256 - ],
257 - 'title' => esc_html__( 'Separate emails with commas', 'uicore-elements' ),
258 - 'render_type' => 'none',
259 - 'dynamic' => [
260 - 'active' => true,
261 - ],
262 - ]
263 - );
264 -
265 - $instance->add_control(
266 - 'form_metadata' . $slug,
267 - [
268 - 'label' => esc_html__( 'Meta Data', 'uicore-elements' ),
269 - 'type' => Controls_Manager::SELECT2,
270 - 'multiple' => true,
271 - 'label_block' => true,
272 - 'separator' => 'before',
273 - 'default' => [
274 - 'date',
275 - 'time',
276 - 'page_url',
277 - 'user_agent',
278 - 'remote_ip',
279 - ],
280 - 'options' => [
281 - 'date' => esc_html__( 'Date', 'uicore-elements' ),
282 - 'time' => esc_html__( 'Time', 'uicore-elements' ),
283 - 'page_url' => esc_html__( 'Page URL', 'uicore-elements' ),
284 - 'user_agent' => esc_html__( 'User Agent', 'uicore-elements' ),
285 - 'remote_ip' => esc_html__( 'Remote IP', 'uicore-elements' ),
286 - ],
287 - 'render_type' => 'none',
288 - ]
289 - );
290 -
291 - $instance->add_control(
292 - 'email_content_type' . $slug,
293 - [
294 - 'label' => esc_html__( 'Send As', 'uicore-elements' ),
295 - 'type' => Controls_Manager::SELECT,
296 - 'default' => 'html',
297 - 'render_type' => 'none',
298 - 'options' => [
299 - 'html' => esc_html__( 'HTML', 'uicore-elements' ),
300 - 'plain' => esc_html__( 'Plain', 'uicore-elements' ),
301 - ],
302 - ]
303 - );
304 - }
305 -
306 144 // Field Render Functions
307 - function build_honeypot_field( $item, $item_index ) {
308 - $this->add_render_attribute( 'honeypot' . $item_index, [
309 - 'class' => [
310 - 'ui-e-field',
145 + function build_honeypot_field($item, $item_index)
146 + {
147 + $this->add_render_attribute('honeypot' . $item_index, [
148 + 'class' => [
149 + 'ui-e-field',
311 150 'ui-e-h-p',
312 - esc_attr( $item['css_classes'] ),
313 - ],
314 - 'name' => 'ui-e-h-p',
315 - 'id' => 'ui-e-h-p',
316 - ] );
151 + esc_attr($item['css_classes']),
152 + ],
153 + 'name' => 'ui-e-h-p',
154 + 'id' => 'ui-e-h-p',
155 + 'autocomplete' => 'off',
156 + ]);
317 157
318 - if ( $item['placeholder'] ) {
319 - $this->add_render_attribute( 'honeypot' . $item_index, 'placeholder', $item['placeholder'] );
320 - }
158 + if ($item['placeholder']) {
159 + $this->add_render_attribute('honeypot' . $item_index, 'placeholder', $item['placeholder']);
160 + }
321 161
322 - if ( $item['required'] ) {
323 - $this->add_required_attribute( 'honeypot' . $item_index );
324 - }
162 + if ($item['required']) {
163 + $this->add_required_attribute('honeypot' . $item_index);
164 + }
325 165
326 - $value = empty( $item['field_value'] ) ? '' : $item['field_value'];
166 + $value = empty($item['field_value']) ? '' : $item['field_value'];
327 167
328 - return '<input ' . $this->get_render_attribute_string( 'honeypot' . $item_index ) . ' tabindex="-1">' . $value . '</input>';
329 - }
330 - function build_textarea_field( $item, $item_index ) {
331 - $this->add_render_attribute( 'textarea' . $item_index, [
332 - 'class' => [
333 - 'ui-e-field',
334 - esc_attr( $item['css_classes'] ),
335 - ],
336 - 'name' => $this->get_attribute_name( $item ),
337 - 'id' => $this->get_attribute_id( $item ),
338 - 'rows' => $item['rows'],
339 - ] );
168 + return '<input ' . $this->get_render_attribute_string('honeypot' . $item_index) . ' tabindex="-1">' . esc_html($value) . '</input>';
169 + }
170 + function build_textarea_field($item, $item_index)
171 + {
172 + $this->add_render_attribute('textarea' . $item_index, [
173 + 'class' => [
174 + 'ui-e-field',
175 + esc_attr($item['css_classes']),
176 + ],
177 + 'name' => $this->get_attribute_name($item),
178 + 'id' => $this->get_attribute_id($item),
179 + 'rows' => $item['rows'],
180 + ]);
340 181
341 - if ( $item['placeholder'] ) {
342 - $this->add_render_attribute( 'textarea' . $item_index, 'placeholder', $item['placeholder'] );
343 - }
182 + if ($item['placeholder']) {
183 + $this->add_render_attribute('textarea' . $item_index, 'placeholder', $item['placeholder']);
184 + }
344 185
345 - if ( $item['required'] ) {
346 - $this->add_required_attribute( 'textarea' . $item_index );
347 - }
186 + if ($item['required']) {
187 + $this->add_required_attribute('textarea' . $item_index);
188 + }
348 189
349 - $value = empty( $item['field_value'] ) ? '' : $item['field_value'];
190 + $value = empty($item['field_value']) ? '' : $item['field_value'];
350 191
351 - return '<textarea ' . $this->get_render_attribute_string( 'textarea' . $item_index ) . '>' . $value . '</textarea>';
352 - }
353 - function build_select_field( $item, $i ) {
354 - $this->add_render_attribute(
355 - [
356 - 'select-wrapper' . $i => [
357 - 'class' => [
358 - 'ui-e-field',
359 - 'ui-e-field-select',
192 + return '<textarea ' . $this->get_render_attribute_string('textarea' . $item_index) . '>' . esc_textarea($value) . '</textarea>';
193 + }
194 + function build_select_field($item, $i)
195 + {
196 + $this->add_render_attribute(
197 + [
198 + 'select-wrapper' . $i => [
199 + 'class' => [
200 + 'ui-e-field',
201 + 'ui-e-field-select',
360 202 'ui-e-field-subgroup',
361 - esc_attr( $item['css_classes'] ),
362 - ],
363 - ],
364 - 'select' . $i => [
365 - 'name' => $this->get_attribute_name( $item ) . ( ! empty( $item['allow_multiple'] ) ? '[]' : '' ),
366 - 'id' => $this->get_attribute_id( $item ),
367 - 'class' => [
368 - 'ui-e-field-textual',
369 - ],
370 - ],
371 - ]
372 - );
203 + esc_attr($item['css_classes']),
204 + ],
205 + ],
206 + 'select' . $i => [
207 + 'name' => $this->get_attribute_name($item) . (! empty($item['allow_multiple']) ? '[]' : ''),
208 + 'id' => $this->get_attribute_id($item),
209 + 'class' => [
210 + 'ui-e-field-textual',
211 + ],
212 + ],
213 + ]
214 + );
373 215
374 - if ( $item['required'] ) {
375 - $this->add_required_attribute( 'select' . $i );
376 - }
216 + if ($item['required']) {
217 + $this->add_required_attribute('select' . $i);
218 + }
377 219
378 - if ( $item['allow_multiple'] ) {
379 - $this->add_render_attribute( 'select' . $i, 'multiple' );
380 - if ( ! empty( $item['select_size'] ) ) {
381 - $this->add_render_attribute( 'select' . $i, 'size', $item['select_size'] );
382 - }
383 - }
220 + if ($item['allow_multiple']) {
221 + $this->add_render_attribute('select' . $i, 'multiple');
222 + if (! empty($item['select_size'])) {
223 + $this->add_render_attribute('select' . $i, 'size', $item['select_size']);
224 + }
225 + }
384 226
385 - $options = preg_split( "/\\r\\n|\\r|\\n/", $item['field_options'] );
227 + $options = preg_split("/\\r\\n|\\r|\\n/", $item['field_options']);
386 228
387 - if ( ! $options ) {
388 - return '';
389 - }
229 + if (! $options) {
230 + return '';
231 + }
390 232
391 - ob_start();
392 - ?>
393 - <div <?php $this->print_render_attribute_string( 'select-wrapper' . $i ); ?>>
394 - <select <?php $this->print_render_attribute_string( 'select' . $i ); ?>>
395 - <?php
396 - foreach ( $options as $key => $option ) {
397 - $option_id = $item['custom_id'] . $key;
398 - $option_value = esc_attr( $option );
399 - $option_label = esc_html( $option );
233 + ob_start();
234 +?>
235 + <div <?php $this->print_render_attribute_string('select-wrapper' . $i); ?>>
236 + <select <?php $this->print_render_attribute_string('select' . $i); ?>>
237 + <?php
238 + foreach ($options as $key => $option) {
239 + $option_id = $item['custom_id'] . $key;
240 + $option_value = esc_attr($option);
241 + $option_label = esc_html($option);
400 242
401 - if ( false !== strpos( $option, '|' ) ) {
402 - list( $label, $value ) = explode( '|', $option );
403 - $option_value = esc_attr( $value );
404 - $option_label = esc_html( $label );
405 - }
243 + if (false !== strpos($option, '|')) {
244 + list($label, $value) = explode('|', $option);
245 + $option_value = esc_attr($value);
246 + $option_label = esc_html($label);
247 + }
406 248
407 - $this->add_render_attribute( $option_id, 'value', $option_value );
249 + $this->add_render_attribute($option_id, 'value', $option_value);
408 250
409 - // Support multiple selected values
410 - if ( ! empty( $item['field_value'] ) && in_array( $option_value, explode( ',', $item['field_value'] ) ) ) {
411 - $this->add_render_attribute( $option_id, 'selected', 'selected' );
412 - } ?>
413 - <option <?php $this->print_render_attribute_string( $option_id ); ?>><?php
414 - // PHPCS - $option_label is already escaped
415 - echo $option_label; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></option>
416 - <?php } ?>
417 - </select>
418 - </div>
419 - <?php
251 + // Support multiple selected values
252 + if (! empty($item['field_value']) && in_array($option_value, explode(',', $item['field_value']))) {
253 + $this->add_render_attribute($option_id, 'selected', 'selected');
254 + } ?>
255 + <option <?php $this->print_render_attribute_string($option_id); ?>><?php
256 + // PHPCS - $option_label is already escaped
257 + echo $option_label; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
258 + ?></option>
259 + <?php } ?>
260 + </select>
261 + </div>
262 + <?php
420 263
421 - $select = ob_get_clean();
422 - return $select;
423 - }
424 - function build_radio_checkbox_field( $item, $item_index, $type ) {
425 - $options = preg_split( "/\\r\\n|\\r|\\n/", $item['field_options'] );
426 - $html = '';
427 - if ( $options ) {
428 - $html .= '<div class="ui-e-field-subgroup ' . esc_attr( $item['css_classes'] ) . ' ' . $item['inline_list'] . '">';
429 - foreach ( $options as $key => $option ) {
430 - $element_id = $item['custom_id'] . $key;
431 - $html_id = $this->get_attribute_id( $item ) . '-' . $key;
432 - $option_label = $option;
433 - $option_value = $option;
434 - if ( false !== strpos( $option, '|' ) ) {
435 - list( $option_label, $option_value ) = explode( '|', $option );
436 - }
264 + $select = ob_get_clean();
265 + return $select;
266 + }
267 + function build_radio_checkbox_field($item, $item_index, $type)
268 + {
269 + $options = preg_split("/\\r\\n|\\r|\\n/", $item['field_options']);
270 + $html = '';
271 + if ($options) {
272 + $html .= '<div class="ui-e-field-subgroup ' . esc_attr($item['css_classes']) . ' ' . esc_attr($item['inline_list']) . '">';
273 + foreach ($options as $key => $option) {
274 + $element_id = $item['custom_id'] . $key;
275 + $html_id = $this->get_attribute_id($item) . '-' . $key;
276 + $option_label = $option;
277 + $option_value = $option;
278 + if (false !== strpos($option, '|')) {
279 + list($option_label, $option_value) = explode('|', $option);
280 + }
437 281
438 - $this->add_render_attribute(
439 - $element_id,
440 - [
441 - 'type' => $type,
442 - 'value' => $option_value,
443 - 'id' => $html_id,
444 - 'name' => $this->get_attribute_name( $item ) . ( ( 'checkbox' === $type && count( $options ) > 1 ) ? '[]' : '' ),
445 - ]
446 - );
282 + $this->add_render_attribute(
283 + $element_id,
284 + [
285 + 'type' => $type,
286 + 'value' => $option_value,
287 + 'id' => $html_id,
288 + 'name' => $this->get_attribute_name($item) . (('checkbox' === $type && count($options) > 1) ? '[]' : ''),
289 + ]
290 + );
447 291
448 - if ( ! empty( $item['field_value'] ) && $option_value === $item['field_value'] ) {
449 - $this->add_render_attribute( $element_id, 'checked', 'checked' );
450 - }
292 + if ($item['required']) {
293 + $this->add_required_attribute($element_id, true);
294 + }
451 295
452 - if ( $item['required'] && 'radio' === $type ) {
453 - $this->add_required_attribute( $element_id );
454 - }
296 + if (! empty($item['field_value']) && $option_value === $item['field_value']) {
297 + $this->add_render_attribute($element_id, 'checked', 'checked');
298 + }
455 299
456 - $html .= '<span class="ui-e-field-option"><input ' . $this->get_render_attribute_string( $element_id ) . '> <label for="' . $html_id . '">' . $option_label . '</label></span>';
457 - }
458 - $html .= '</div>';
459 - }
300 + if ($item['required'] && 'radio' === $type) {
301 + $this->add_required_attribute($element_id);
302 + }
460 303
461 - return $html;
462 - }
463 - function build_acceptance_field($item, $item_index) {
464 - $text = '';
465 - $this->add_render_attribute( 'input' . $item_index, 'class', 'ui-e-acceptance-field' );
466 - $this->add_render_attribute( 'input' . $item_index, 'type', 'checkbox', true );
304 + $html .= '<span class="ui-e-field-option">';
305 + $html .= '<input ' . $this->get_render_attribute_string($element_id) . '>';
306 + $html .= '<label for="' . $html_id . '">';
307 + $html .= esc_html($option_label);
308 + $html .= '</label></span>';
309 + }
310 + $html .= '</div>';
311 + }
467 312
468 - if ( ! empty( $item['acceptance_text'] ) ) {
469 - $text = '<label for="' . $this->get_attribute_id( $item ) . '">' . $item['acceptance_text'] . '</label>';
470 - }
313 + return $html;
314 + }
315 + function build_acceptance_field($item, $item_index)
316 + {
317 + $text = '';
318 + $this->add_render_attribute('input' . $item_index, 'class', 'ui-e-acceptance-field');
319 + $this->add_render_attribute('input' . $item_index, 'type', 'checkbox', true);
471 320
472 - if ( ! empty( $item['checked_by_default'] ) ) {
473 - $this->add_render_attribute( 'input' . $item_index, 'checked', 'checked' );
474 - }
321 + if (! empty($item['acceptance_text'])) {
322 + $text = '<label for="' . $this->get_attribute_id($item) . '">' . Helper::esc_string($item['acceptance_text']) . '</label>';
323 + }
475 324
476 - ?>
477 - <div class="ui-e-field-subgroup <?php echo esc_attr( $item['css_classes'] );?>">
478 - <input <?php $this->print_render_attribute_string( 'input' . $item_index ); ?>>
479 - <?php // PHPCS - the variables $text is safe.
480 - echo $text; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
481 - </div>
482 - <?php
483 - }
484 - function form_fields_render_attributes( $i, $instance, $item ) {
485 - $this->add_render_attribute(
486 - [
487 - 'field-group' . $i => [
488 - 'class' => [
489 - 'ui-e-field-type-' . $item['field_type'],
490 - 'ui-e-field-group',
491 - 'elementor-column',
492 - 'ui-e-field-group-' . $item['custom_id'],
493 - ],
494 - ],
495 - 'input' . $i => [
496 - 'type' => $item['field_type'],
497 - 'name' => $this->get_attribute_name( $item ),
498 - 'id' => $this->get_attribute_id( $item ),
499 - 'class' => [
500 - 'ui-e-field',
501 - empty( $item['css_classes'] ) ? '' : esc_attr( $item['css_classes'] ),
502 - ],
503 - ],
504 - 'label' . $i => [
505 - 'for' => $this->get_attribute_id( $item ),
506 - 'class' => 'ui-e-label',
507 - ],
508 - ]
509 - );
325 + if (! empty($item['checked_by_default'])) {
326 + $this->add_render_attribute('input' . $item_index, 'checked', 'checked');
327 + }
510 328
511 - if ( empty( $item['width'] ) ) {
512 - $item['width'] = '100';
513 - }
329 + ?>
330 + <div class="ui-e-field-subgroup <?php echo esc_attr($item['css_classes']); ?>">
331 + <input <?php $this->print_render_attribute_string('input' . $item_index); ?>>
332 + <?php // PHPCS - the variables $text is safe.
333 + echo $text; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
334 + ?>
335 + </div>
336 + <?php
337 + }
338 + function form_fields_render_attributes($i, $instance, $item)
339 + {
340 + $this->add_render_attribute(
341 + [
342 + 'field-group' . $i => [
343 + 'class' => [
344 + 'ui-e-field-type-' . $item['field_type'],
345 + 'ui-e-field-group',
346 + 'elementor-column',
347 + 'ui-e-field-group-' . $item['custom_id'],
348 + ],
349 + ],
350 + 'input' . $i => [
351 + 'type' => $item['field_type'],
352 + 'name' => $this->get_attribute_name($item),
353 + 'id' => $this->get_attribute_id($item),
354 + 'class' => [
355 + 'ui-e-field',
356 + empty($item['css_classes']) ? '' : esc_attr($item['css_classes']),
357 + ],
358 + ],
359 + 'label' . $i => [
360 + 'for' => $this->get_attribute_id($item),
361 + 'class' => 'ui-e-label',
362 + ],
363 + ]
364 + );
514 365
515 - $this->add_render_attribute( 'field-group' . $i, 'class', 'elementor-col-' . $item['width'] );
366 + if (empty($item['width'])) {
367 + $item['width'] = '100';
368 + }
516 369
517 - if ( ! empty( $item['width_tablet'] ) ) {
518 - $this->add_render_attribute( 'field-group' . $i, 'class', 'elementor-md-' . $item['width_tablet'] );
519 - }
370 + $this->add_render_attribute('field-group' . $i, 'class', 'elementor-col-' . $item['width']);
520 371
521 - if ( $item['allow_multiple'] ) {
522 - $this->add_render_attribute( 'field-group' . $i, 'class', 'ui-e-field-type-' . $item['field_type'] . '-multiple' );
523 - }
372 + if (! empty($item['width_tablet'])) {
373 + $this->add_render_attribute('field-group' . $i, 'class', 'elementor-md-' . $item['width_tablet']);
374 + }
524 375
525 - if ( ! empty( $item['width_mobile'] ) ) {
526 - $this->add_render_attribute( 'field-group' . $i, 'class', 'elementor-sm-' . $item['width_mobile'] );
527 - }
376 + if ($item['allow_multiple']) {
377 + $this->add_render_attribute('field-group' . $i, 'class', 'ui-e-field-type-' . $item['field_type'] . '-multiple');
378 + }
528 379
529 - // Allow zero as placeholder.
530 - if ( ! Utils::is_empty( $item['placeholder'] ) ) {
531 - $this->add_render_attribute( 'input' . $i, 'placeholder', $item['placeholder'] );
532 - }
380 + if (! empty($item['width_mobile'])) {
381 + $this->add_render_attribute('field-group' . $i, 'class', 'elementor-sm-' . $item['width_mobile']);
382 + }
533 383
534 - if ( ! empty( $item['field_value'] ) ) {
535 - $this->add_render_attribute( 'input' . $i, 'value', $item['field_value'] );
536 - }
384 + // Allow zero as placeholder.
385 + if (! Utils::is_empty($item['placeholder'])) {
386 + $this->add_render_attribute('input' . $i, 'placeholder', $item['placeholder']);
387 + }
537 388
538 - if ( ! $instance['show_labels'] ) {
539 - $this->add_render_attribute( 'label' . $i, 'class', 'elementor-screen-only' );
540 - }
389 + if (! empty($item['field_value'])) {
390 + $this->add_render_attribute('input' . $i, 'value', $item['field_value']);
391 + }
541 392
542 - if ( ! empty( $item['required'] ) ) {
543 - $class = '';
544 - if ( ! empty( $instance['mark_required'] ) ) {
545 - $class .= ' ui-e-required';
546 - }
547 - $this->add_render_attribute( 'field-group' . $i, 'class', $class );
548 - $this->add_required_attribute( 'input' . $i );
549 - }
550 - }
393 + if (! $instance['show_labels']) {
394 + $this->add_render_attribute('label' . $i, 'class', 'elementor-screen-only');
395 + }
551 396
552 - protected function register_controls() {
397 + if (! empty($item['required'])) {
398 + $class = '';
399 + if (! empty($instance['mark_required'])) {
400 + $class .= ' ui-e-required';
401 + }
402 + $this->add_render_attribute('field-group' . $i, 'class', $class);
403 + $this->add_required_attribute('input' . $i);
404 + }
405 + }
553 406
407 + protected function register_controls()
408 + {
409 +
554 410 // Content Controls
555 411 // Repeater Controls used by `form_fields` control
556 412 $repeater = new Repeater();
557 - $repeater->start_controls_tabs( 'form_fields_tabs' );
413 + $repeater->start_controls_tabs('form_fields_tabs');
558 414
559 - $repeater->start_controls_tab(
560 - 'form_fields_content_tab',
561 - [
562 - 'label' => esc_html__( 'Content', 'uicore-elements' ),
563 - ]
564 - );
415 + $repeater->start_controls_tab(
416 + 'form_fields_content_tab',
417 + [
418 + 'label' => esc_html__('Content', 'uicore-elements'),
419 + ]
420 + );
565 421
566 - $repeater->add_control(
567 - 'field_type',
568 - [
569 - 'label' => esc_html__( 'Type', 'uicore-elements' ),
570 - 'type' => Controls_Manager::SELECT,
571 - 'options' => $this->get_field_types(),
572 - 'default' => 'text',
573 - ]
574 - );
575 - $repeater->add_control(
576 - 'field_label',
577 - [
578 - 'label' => esc_html__( 'Label', 'uicore-elements' ),
579 - 'type' => Controls_Manager::TEXT,
580 - 'default' => '',
581 - 'dynamic' => [
582 - 'active' => true,
583 - ],
584 - ]
585 - );
586 - $repeater->add_control(
587 - 'placeholder',
588 - [
589 - 'label' => esc_html__( 'Placeholder', 'uicore-elements' ),
590 - 'type' => Controls_Manager::TEXT,
591 - 'default' => '',
592 - 'conditions' => [
593 - 'terms' => [
594 - [
595 - 'name' => 'field_type',
596 - 'operator' => 'in',
597 - 'value' => [
598 - 'tel',
599 - 'text',
600 - 'email',
601 - 'textarea',
602 - 'number',
603 - 'url',
604 - 'password',
605 - ],
606 - ],
422 + $repeater->add_control(
423 + 'field_type',
424 + [
425 + 'label' => esc_html__('Type', 'uicore-elements'),
426 + 'type' => Controls_Manager::SELECT,
427 + 'options' => $this->get_field_types(),
428 + 'default' => 'text',
429 + ]
430 + );
431 + $repeater->add_control(
432 + 'field_label',
433 + [
434 + 'label' => esc_html__('Label', 'uicore-elements'),
435 + 'type' => Controls_Manager::TEXT,
436 + 'default' => '',
437 + 'dynamic' => [
438 + 'active' => true,
439 + ],
440 + ]
441 + );
442 + $repeater->add_control(
443 + 'placeholder',
444 + [
445 + 'label' => esc_html__('Placeholder', 'uicore-elements'),
446 + 'type' => Controls_Manager::TEXT,
447 + 'default' => '',
448 + 'conditions' => [
449 + 'terms' => [
450 + [
451 + 'name' => 'field_type',
452 + 'operator' => 'in',
453 + 'value' => [
454 + 'tel',
455 + 'text',
456 + 'email',
457 + 'textarea',
458 + 'number',
459 + 'url',
460 + 'password',
607 461 ],
608 462 ],
609 - 'dynamic' => [
610 - 'active' => true,
611 - ],
612 - ]
613 - );
614 - $repeater->add_control(
615 - 'required',
616 - [
617 - 'label' => esc_html__( 'Required', 'uicore-elements' ),
618 - 'type' => Controls_Manager::SWITCHER,
619 - 'return_value' => 'true',
620 - 'default' => '',
621 - 'conditions' => [
622 - 'terms' => [
623 - [
624 - 'name' => 'field_type',
625 - 'operator' => '!in',
626 - 'value' => [
627 - 'checkbox',
628 - 'recaptcha',
629 - 'recaptcha_v3',
630 - 'hidden',
631 - 'html',
632 - ],
633 - ],
463 + ],
464 + ],
465 + 'dynamic' => [
466 + 'active' => true,
467 + ],
468 + ]
469 + );
470 + $repeater->add_control(
471 + 'required',
472 + [
473 + 'label' => esc_html__('Required', 'uicore-elements'),
474 + 'type' => Controls_Manager::SWITCHER,
475 + 'return_value' => 'true',
476 + 'default' => '',
477 + 'conditions' => [
478 + 'terms' => [
479 + [
480 + 'name' => 'field_type',
481 + 'operator' => '!in',
482 + 'value' => [
483 + 'recaptcha',
484 + 'recaptcha_v3',
485 + 'hidden',
486 + 'html',
634 487 ],
635 488 ],
636 - ]
637 - );
638 - $repeater->add_control(
639 - 'field_options',
640 - [
641 - 'label' => esc_html__( 'Options', 'uicore-elements' ),
642 - 'type' => Controls_Manager::TEXTAREA,
643 - 'default' => '',
644 - 'description' => esc_html__( 'Enter each option in a separate line. To differentiate between label and value, separate them with a pipe char ("|"). For example: First Name|f_name', 'uicore-elements' ),
645 - 'conditions' => [
646 - 'terms' => [
647 - [
648 - 'name' => 'field_type',
649 - 'operator' => 'in',
650 - 'value' => [
651 - 'select',
652 - 'checkbox',
653 - 'radio',
654 - ],
655 - ],
489 + ],
490 + ],
491 + ]
492 + );
493 + $repeater->add_control(
494 + 'field_options',
495 + [
496 + 'label' => esc_html__('Options', 'uicore-elements'),
497 + 'type' => Controls_Manager::TEXTAREA,
498 + 'default' => '',
499 + 'description' => esc_html__('Enter each option in a separate line. To differentiate between label and value, separate them with a pipe char ("|"). For example: First Name|f_name', 'uicore-elements'),
500 + 'conditions' => [
501 + 'terms' => [
502 + [
503 + 'name' => 'field_type',
504 + 'operator' => 'in',
505 + 'value' => [
506 + 'select',
507 + 'checkbox',
508 + 'radio',
656 509 ],
657 510 ],
658 - ]
659 - );
660 - $repeater->add_control(
661 - 'allow_multiple',
662 - [
663 - 'label' => esc_html__( 'Multiple Selection', 'uicore-elements' ),
664 - 'type' => Controls_Manager::SWITCHER,
665 - 'return_value' => 'true',
666 - 'conditions' => [
667 - 'terms' => [
668 - [
669 - 'name' => 'field_type',
670 - 'value' => 'select',
671 - ],
672 - ],
511 + ],
512 + ],
513 + ]
514 + );
515 + $repeater->add_control(
516 + 'allow_multiple',
517 + [
518 + 'label' => esc_html__('Multiple Selection', 'uicore-elements'),
519 + 'type' => Controls_Manager::SWITCHER,
520 + 'return_value' => 'true',
521 + 'conditions' => [
522 + 'terms' => [
523 + [
524 + 'name' => 'field_type',
525 + 'value' => 'select',
673 526 ],
674 - ]
675 - );
676 - $repeater->add_control(
677 - 'select_size',
678 - [
679 - 'label' => esc_html__( 'Rows', 'uicore-elements' ),
680 - 'type' => Controls_Manager::NUMBER,
681 - 'min' => 2,
682 - 'step' => 1,
683 - 'conditions' => [
684 - 'terms' => [
685 - [
686 - 'name' => 'field_type',
687 - 'value' => 'select',
688 - ],
689 - [
690 - 'name' => 'allow_multiple',
691 - 'value' => 'true',
692 - ],
693 - ],
527 + ],
528 + ],
529 + ]
530 + );
531 + $repeater->add_control(
532 + 'select_size',
533 + [
534 + 'label' => esc_html__('Rows', 'uicore-elements'),
535 + 'type' => Controls_Manager::NUMBER,
536 + 'min' => 2,
537 + 'step' => 1,
538 + 'conditions' => [
539 + 'terms' => [
540 + [
541 + 'name' => 'field_type',
542 + 'value' => 'select',
694 543 ],
695 - ]
696 - );
697 - $repeater->add_control(
698 - 'inline_list',
699 - [
700 - 'label' => esc_html__( 'Inline List', 'uicore-elements' ),
701 - 'type' => Controls_Manager::SWITCHER,
702 - 'return_value' => 'ui-e-subgroup-inline',
703 - 'default' => '',
704 - 'conditions' => [
705 - 'terms' => [
706 - [
707 - 'name' => 'field_type',
708 - 'operator' => 'in',
709 - 'value' => [
710 - 'checkbox',
711 - 'radio',
712 - ],
713 - ],
714 - ],
544 + [
545 + 'name' => 'allow_multiple',
546 + 'value' => 'true',
715 547 ],
716 - ]
717 - );
718 - $repeater->add_control(
719 - 'field_html',
720 - [
721 - 'label' => esc_html__( 'HTML', 'uicore-elements' ),
722 - 'type' => Controls_Manager::TEXTAREA,
723 - 'dynamic' => [
724 - 'active' => true,
725 - ],
726 - 'conditions' => [
727 - 'terms' => [
728 - [
729 - 'name' => 'field_type',
730 - 'value' => 'html',
731 - ],
548 + ],
549 + ],
550 + ]
551 + );
552 + $repeater->add_control(
553 + 'inline_list',
554 + [
555 + 'label' => esc_html__('Inline List', 'uicore-elements'),
556 + 'type' => Controls_Manager::SWITCHER,
557 + 'return_value' => 'ui-e-subgroup-inline',
558 + 'default' => '',
559 + 'conditions' => [
560 + 'terms' => [
561 + [
562 + 'name' => 'field_type',
563 + 'operator' => 'in',
564 + 'value' => [
565 + 'checkbox',
566 + 'radio',
732 567 ],
733 568 ],
734 - ]
735 - );
736 - $repeater->add_control(
737 - 'acceptance_text',
738 - [
739 - 'label' => esc_html__( 'Acceptance Text', 'uicore-elements' ),
740 - 'type' => Controls_Manager::TEXTAREA,
741 - 'condition' => [
742 - 'field_type' => 'acceptance',
743 - ],
744 - ],
745 - );
746 - $repeater->add_control(
747 - 'checked_by_default',
748 - [
749 - 'label' => esc_html__( 'Checked by Default', 'uicore-elements' ),
750 - 'type' => Controls_Manager::SWITCHER,
751 - 'condition' => [
752 - 'field_type' => 'acceptance',
753 - ],
754 - ],
755 - );
756 - $repeater->add_responsive_control(
757 - 'width',
758 - [
759 - 'label' => esc_html__( 'Column Width', 'uicore-elements' ),
760 - 'type' => Controls_Manager::SELECT,
761 - 'options' => [
762 - '' => esc_html__( 'Default', 'uicore-elements' ),
763 - '100' => '100%',
764 - '80' => '80%',
765 - '75' => '75%',
766 - '70' => '70%',
767 - '66' => '66%',
768 - '60' => '60%',
769 - '50' => '50%',
770 - '40' => '40%',
771 - '33' => '33%',
772 - '30' => '30%',
773 - '25' => '25%',
774 - '20' => '20%',
569 + ],
570 + ],
571 + ]
572 + );
573 + $repeater->add_control(
574 + 'field_html',
575 + [
576 + 'label' => esc_html__('HTML', 'uicore-elements'),
577 + 'type' => Controls_Manager::TEXTAREA,
578 + 'dynamic' => [
579 + 'active' => true,
580 + ],
581 + 'conditions' => [
582 + 'terms' => [
583 + [
584 + 'name' => 'field_type',
585 + 'value' => 'html',
775 586 ],
776 - 'default' => '100',
777 - 'conditions' => [
778 - 'terms' => [
779 - [
780 - 'name' => 'field_type',
781 - 'operator' => '!in',
782 - 'value' => [
783 - 'hidden',
784 - 'recaptcha',
785 - 'recaptcha_v3'
786 - ],
787 - ],
587 + ],
588 + ],
589 + ]
590 + );
591 + $repeater->add_control(
592 + 'acceptance_text',
593 + [
594 + 'label' => esc_html__('Acceptance Text', 'uicore-elements'),
595 + 'type' => Controls_Manager::TEXTAREA,
596 + 'condition' => [
597 + 'field_type' => 'acceptance',
598 + ],
599 + ],
600 + );
601 + $repeater->add_control(
602 + 'checked_by_default',
603 + [
604 + 'label' => esc_html__('Checked by Default', 'uicore-elements'),
605 + 'type' => Controls_Manager::SWITCHER,
606 + 'condition' => [
607 + 'field_type' => 'acceptance',
608 + ],
609 + ],
610 + );
611 + $repeater->add_responsive_control(
612 + 'width',
613 + [
614 + 'label' => esc_html__('Column Width', 'uicore-elements'),
615 + 'type' => Controls_Manager::SELECT,
616 + 'options' => [
617 + '' => esc_html__('Default', 'uicore-elements'),
618 + '100' => '100%',
619 + '80' => '80%',
620 + '75' => '75%',
621 + '70' => '70%',
622 + '66' => '66%',
623 + '60' => '60%',
624 + '50' => '50%',
625 + '40' => '40%',
626 + '33' => '33%',
627 + '30' => '30%',
628 + '25' => '25%',
629 + '20' => '20%',
630 + ],
631 + 'default' => '100',
632 + 'conditions' => [
633 + 'terms' => [
634 + [
635 + 'name' => 'field_type',
636 + 'operator' => '!in',
637 + 'value' => [
638 + 'hidden',
639 + 'recaptcha',
640 + 'recaptcha_v3'
788 641 ],
789 642 ],
790 - ]
791 - );
792 - $repeater->add_control(
793 - 'rows',
794 - [
795 - 'label' => esc_html__( 'Rows', 'uicore-elements' ),
796 - 'type' => Controls_Manager::NUMBER,
797 - 'default' => 4,
798 - 'conditions' => [
799 - 'terms' => [
800 - [
801 - 'name' => 'field_type',
802 - 'value' => 'textarea',
803 - ],
804 - ],
643 + ],
644 + ],
645 + ]
646 + );
647 + $repeater->add_control(
648 + 'rows',
649 + [
650 + 'label' => esc_html__('Rows', 'uicore-elements'),
651 + 'type' => Controls_Manager::NUMBER,
652 + 'default' => 4,
653 + 'conditions' => [
654 + 'terms' => [
655 + [
656 + 'name' => 'field_type',
657 + 'value' => 'textarea',
805 658 ],
806 - ]
807 - );
808 - $repeater->add_control(
809 - 'recaptcha_hide',
810 - [
811 - 'label' => esc_html__( 'Badge', 'uicore-elements' ),
812 - 'type' => Controls_Manager::SELECT,
813 - 'default' => 'hidden',
814 - 'options' => [
815 - 'hidden' => esc_html__( 'Hidden', 'uicore-elements' ),
816 - 'visible' => esc_html__( 'Visible', 'uicore-elements' )
817 - ],
818 - 'condition' => [
819 - 'field_type' => 'recaptcha_v3',
820 - ],
821 - 'selectors' => [
822 - '.grecaptcha-badge' => 'visibility: {{VALUE}};',
823 - ],
824 - ]
825 - );
826 - $recaptcha_keys = (!get_option('uicore_elements_recaptcha_secret_key') && !get_option('uicore_elements_recaptcha_site_key')) ? true : false; // Check if recaptcha API keys were set
827 - $repeater->add_control(
828 - 'recaptcha_warning',
829 - [
830 - 'type' => Controls_Manager::ALERT,
831 - 'alert_type' => 'warning',
832 - 'dismissible' => false,
833 - 'heading' => esc_html__("You haven't set your reCAPTCHA API keys yet.", 'uicore-elements'),
834 - 'content' => Helper::get_admin_settings_url(esc_html__("Click here to configure your API keys.", 'uicore-elements' )),
835 - 'condition' => [
836 - 'field_type' => $recaptcha_keys ? ['recaptcha', 'recaptcha_v3'] : [],
837 - ]
838 - ]
839 - );
659 + ],
660 + ],
661 + ]
662 + );
663 + $repeater->add_control(
664 + 'recaptcha_hide',
665 + [
666 + 'label' => esc_html__('Badge', 'uicore-elements'),
667 + 'type' => Controls_Manager::SELECT,
668 + 'default' => 'hidden',
669 + 'options' => [
670 + 'hidden' => esc_html__('Hidden', 'uicore-elements'),
671 + 'visible' => esc_html__('Visible', 'uicore-elements')
672 + ],
673 + 'condition' => [
674 + 'field_type' => 'recaptcha_v3',
675 + ],
676 + 'selectors' => [
677 + '.grecaptcha-badge' => 'visibility: {{VALUE}};',
678 + ],
679 + ]
680 + );
681 + $recaptcha_keys = (!get_option('uicore_elements_recaptcha_secret_key') && !get_option('uicore_elements_recaptcha_site_key')) ? true : false; // Check if recaptcha API keys were set
682 + $repeater->add_control(
683 + 'recaptcha_warning',
684 + [
685 + 'type' => Controls_Manager::ALERT,
686 + 'alert_type' => 'warning',
687 + 'dismissible' => false,
688 + 'heading' => esc_html__("You haven't set your reCAPTCHA API keys yet.", 'uicore-elements'),
689 + 'content' => Helper::get_admin_settings_url(esc_html__("Click here to configure your API keys.", 'uicore-elements')),
690 + 'condition' => [
691 + 'field_type' => $recaptcha_keys ? ['recaptcha', 'recaptcha_v3'] : [],
692 + ]
693 + ]
694 + );
840 695
841 - $repeater->end_controls_tab();
696 + $repeater->end_controls_tab();
842 697
843 - $repeater->start_controls_tab(
844 - 'form_fields_advanced_tab',
845 - [
846 - 'label' => esc_html__( 'Advanced', 'uicore-elements' ),
847 - 'condition' => [
848 - 'field_type!' => ['html', 'address' ],
849 - ],
850 - ]
851 - );
698 + $repeater->start_controls_tab(
699 + 'form_fields_advanced_tab',
700 + [
701 + 'label' => esc_html__('Advanced', 'uicore-elements'),
702 + 'condition' => [
703 + 'field_type!' => ['html', 'address'],
704 + ],
705 + ]
706 + );
852 707
853 - $repeater->add_control(
854 - 'field_value',
855 - [
856 - 'label' => esc_html__( 'Default Value', 'uicore-elements' ),
857 - 'type' => Controls_Manager::TEXT,
858 - 'default' => '',
859 - 'dynamic' => [
860 - 'active' => true,
861 - ],
862 - 'ai' => [
863 - 'active' => false,
864 - ],
865 - 'conditions' => [
866 - 'terms' => [
867 - [
868 - 'name' => 'field_type',
869 - 'operator' => 'in',
870 - 'value' => [
871 - 'text',
872 - 'email',
873 - 'textarea',
874 - 'url',
875 - 'tel',
876 - 'radio',
877 - 'select',
878 - 'number',
879 - 'date',
880 - 'time',
881 - 'hidden',
882 - ],
883 - ],
708 + $repeater->add_control(
709 + 'field_value',
710 + [
711 + 'label' => esc_html__('Default Value', 'uicore-elements'),
712 + 'type' => Controls_Manager::TEXT,
713 + 'default' => '',
714 + 'dynamic' => [
715 + 'active' => true,
716 + ],
717 + 'ai' => [
718 + 'active' => false,
719 + ],
720 + 'conditions' => [
721 + 'terms' => [
722 + [
723 + 'name' => 'field_type',
724 + 'operator' => 'in',
725 + 'value' => [
726 + 'text',
727 + 'email',
728 + 'textarea',
729 + 'url',
730 + 'tel',
731 + 'radio',
732 + 'select',
733 + 'number',
734 + 'date',
735 + 'time',
736 + 'hidden',
884 737 ],
885 738 ],
886 - ]
887 - );
888 - $repeater->add_control(
889 - 'custom_id',
890 - [
891 - 'label' => esc_html__( 'ID', 'uicore-elements' ),
892 - 'type' => Controls_Manager::TEXT,
893 - 'description' => esc_html__( 'Please make sure the ID is unique and not used elsewhere in this form. This field allows `A-z 0-9` & underscore chars without spaces.', 'uicore-elements' ),
894 - 'render_type' => 'none',
895 - 'required' => true,
896 - 'dynamic' => [
897 - 'active' => true,
898 - ],
899 - 'ai' => [
900 - 'active' => false,
901 - ],
902 - ]
903 - );
904 - $repeater->add_control(
905 - 'css_classes',
906 - [
907 - 'label' => esc_html__( 'Custom Class', 'uicore-elements' ),
908 - 'type' => Controls_Manager::TEXT,
909 - 'default' => '',
910 - 'ai' => [
911 - 'active' => false,
912 - ],
913 - 'placeholder' => esc_html__( 'e.g: my-class', 'uicore-elements' ),
914 - ]
915 - );
916 - $shortcode_template = '{{ view.container.settings.get( \'custom_id\' ) }}';
917 - $repeater->add_control(
918 - 'shortcode',
919 - [
920 - 'label' => esc_html__( 'Shortcode', 'uicore-elements' ),
921 - 'type' => Controls_Manager::RAW_HTML,
922 - 'classes' => 'forms-field-shortcode',
923 - 'raw' => '<input class="elementor-form-field-shortcode" value=\'[field id="' . $shortcode_template . '"]\' readonly />',
924 - 'label_block' => false,
925 - ]
926 - );
739 + ],
740 + ],
741 + ]
742 + );
743 + $repeater->add_control(
744 + 'custom_id',
745 + [
746 + 'label' => esc_html__('ID', 'uicore-elements'),
747 + 'type' => Controls_Manager::TEXT,
748 + 'description' => esc_html__('Please make sure the ID is unique and not used elsewhere in this form. This field allows `A-z 0-9` & underscore chars without spaces.', 'uicore-elements'),
749 + 'render_type' => 'none',
750 + 'required' => true,
751 + 'dynamic' => [
752 + 'active' => true,
753 + ],
754 + 'ai' => [
755 + 'active' => false,
756 + ],
757 + ]
758 + );
759 + $repeater->add_control(
760 + 'css_classes',
761 + [
762 + 'label' => esc_html__('Custom Class', 'uicore-elements'),
763 + 'type' => Controls_Manager::TEXT,
764 + 'default' => '',
765 + 'ai' => [
766 + 'active' => false,
767 + ],
768 + 'placeholder' => esc_html__('e.g: my-class', 'uicore-elements'),
769 + ]
770 + );
771 + $shortcode_template = '{{ view.container.settings.get( \'custom_id\' ) }}';
772 + $repeater->add_control(
773 + 'shortcode',
774 + [
775 + 'label' => esc_html__('Shortcode', 'uicore-elements'),
776 + 'type' => Controls_Manager::RAW_HTML,
777 + 'classes' => 'forms-field-shortcode',
778 + 'raw' => '<input class="elementor-form-field-shortcode" value=\'[field id="' . $shortcode_template . '"]\' readonly />',
779 + 'label_block' => false,
780 + ]
781 + );
927 782
928 - $repeater->end_controls_tab();
783 + $repeater->end_controls_tab();
929 784
930 785 $repeater->end_controls_tabs();
931 786
932 787 $this->start_controls_section(
@@ -931,267 +786,243 @@
931 786
932 787 $this->start_controls_section(
933 788 'section_form_fields',
934 789 [
935 - 'label' => esc_html__( 'Form Fields', 'uicore-elements' ),
790 + 'label' => esc_html__('Form Fields', 'uicore-elements'),
936 791 ]
937 792 );
938 793
939 794
940 - $this->add_control(
941 - 'form_name',
942 - [
943 - 'label' => esc_html__( 'Form Name', 'uicore-elements' ),
944 - 'type' => Controls_Manager::TEXT,
945 - 'default' => esc_html__( 'New Form', 'uicore-elements' ),
946 - 'placeholder' => esc_html__( 'Form Name', 'uicore-elements' ),
947 - ]
948 - );
949 - $this->add_control(
950 - 'form_fields',
951 - [
952 - 'type' => Controls_Manager::REPEATER,
953 - 'fields' => $repeater->get_controls(),
954 - 'default' => [
955 - [
956 - 'custom_id' => 'name',
957 - 'field_type' => 'text',
958 - 'field_label' => esc_html__( 'Name', 'uicore-elements' ),
959 - 'placeholder' => esc_html__( 'Name', 'uicore-elements' ),
960 - 'width' => '100',
961 - 'dynamic' => [
962 - 'active' => true,
963 - ],
795 + $this->add_control(
796 + 'form_name',
797 + [
798 + 'label' => esc_html__('Form Name', 'uicore-elements'),
799 + 'type' => Controls_Manager::TEXT,
800 + 'default' => esc_html__('New Form', 'uicore-elements'),
801 + 'placeholder' => esc_html__('Form Name', 'uicore-elements'),
802 + ]
803 + );
804 + $this->add_control(
805 + 'form_fields',
806 + [
807 + 'type' => Controls_Manager::REPEATER,
808 + 'fields' => $repeater->get_controls(),
809 + 'default' => [
810 + [
811 + 'custom_id' => 'name',
812 + 'field_type' => 'text',
813 + 'field_label' => esc_html__('Name', 'uicore-elements'),
814 + 'placeholder' => esc_html__('Name', 'uicore-elements'),
815 + 'width' => '100',
816 + 'dynamic' => [
817 + 'active' => true,
964 818 ],
965 - [
966 - 'custom_id' => 'email',
967 - 'field_type' => 'email',
968 - 'required' => 'true',
969 - 'field_label' => esc_html__( 'Email', 'uicore-elements' ),
970 - 'placeholder' => esc_html__( 'Email', 'uicore-elements' ),
971 - 'width' => '100',
972 - ],
973 - [
974 - 'custom_id' => 'address',
975 - 'field_type' => 'address',
976 - 'field_label' => esc_html__( 'address (honeypot)', 'uicore-elements' ),
977 - 'placeholder' => esc_html__( 'address', 'uicore-elements' ),
978 - 'width' => '100',
979 - ],
980 - [
981 - 'custom_id' => 'message',
982 - 'field_type' => 'textarea',
983 - 'field_label' => esc_html__( 'Message', 'uicore-elements' ),
984 - 'placeholder' => esc_html__( 'Message', 'uicore-elements' ),
985 - 'width' => '100',
986 - ],
987 819 ],
988 - 'title_field' => '{{{ field_label }}}',
989 - ]
990 - );
991 - $this->add_control(
992 - 'show_labels',
993 - [
994 - 'label' => esc_html__( 'Label', 'uicore-elements' ),
995 - 'type' => Controls_Manager::SWITCHER,
996 - 'label_on' => esc_html__( 'Show', 'uicore-elements' ),
997 - 'label_off' => esc_html__( 'Hide', 'uicore-elements' ),
998 - 'return_value' => 'true',
999 - 'default' => 'true',
1000 - 'separator' => 'before',
1001 - ]
1002 - );
1003 - $this->add_control(
1004 - 'mark_required',
1005 - [
1006 - 'label' => esc_html__( 'Required Mark', 'uicore-elements' ),
1007 - 'type' => Controls_Manager::SWITCHER,
1008 - 'label_on' => esc_html__( 'Show', 'uicore-elements' ),
1009 - 'label_off' => esc_html__( 'Hide', 'uicore-elements' ),
1010 - 'default' => '',
1011 - 'render_type' => 'template',
1012 - 'condition' => [
1013 - 'show_labels!' => '',
820 + [
821 + 'custom_id' => 'email',
822 + 'field_type' => 'email',
823 + 'required' => 'true',
824 + 'field_label' => esc_html__('Email', 'uicore-elements'),
825 + 'placeholder' => esc_html__('Email', 'uicore-elements'),
826 + 'width' => '100',
1014 827 ],
1015 - ]
1016 - );
828 + [
829 + 'custom_id' => 'address',
830 + 'field_type' => 'address',
831 + 'field_label' => esc_html__('address (honeypot)', 'uicore-elements'),
832 + 'placeholder' => esc_html__('address', 'uicore-elements'),
833 + 'width' => '100',
834 + ],
835 + [
836 + 'custom_id' => 'message',
837 + 'field_type' => 'textarea',
838 + 'field_label' => esc_html__('Message', 'uicore-elements'),
839 + 'placeholder' => esc_html__('Message', 'uicore-elements'),
840 + 'width' => '100',
841 + ],
842 + ],
843 + 'title_field' => '{{ field_label }}',
844 + ]
845 + );
846 + $this->add_control(
847 + 'show_labels',
848 + [
849 + 'label' => esc_html__('Label', 'uicore-elements'),
850 + 'type' => Controls_Manager::SWITCHER,
851 + 'label_on' => esc_html__('Show', 'uicore-elements'),
852 + 'label_off' => esc_html__('Hide', 'uicore-elements'),
853 + 'return_value' => 'true',
854 + 'default' => 'true',
855 + 'separator' => 'before',
856 + ]
857 + );
858 + $this->add_control(
859 + 'mark_required',
860 + [
861 + 'label' => esc_html__('Required Mark', 'uicore-elements'),
862 + 'type' => Controls_Manager::SWITCHER,
863 + 'label_on' => esc_html__('Show', 'uicore-elements'),
864 + 'label_off' => esc_html__('Hide', 'uicore-elements'),
865 + 'default' => '',
866 + 'render_type' => 'template',
867 + 'condition' => [
868 + 'show_labels!' => '',
869 + ],
870 + ]
871 + );
1017 872
1018 873 $this->end_controls_section();
1019 874
1020 - $this->start_controls_section(
875 + $this->start_controls_section(
1021 876 'section_buttons',
1022 877 [
1023 - 'label' => esc_html__( 'Button', 'uicore-elements' ),
878 + 'label' => esc_html__('Button', 'uicore-elements'),
1024 879 ]
1025 880 );
1026 881
1027 - $this->add_responsive_control(
1028 - 'button_width',
1029 - [
1030 - 'label' => esc_html__( 'Column Width', 'uicore-elements' ),
1031 - 'type' => Controls_Manager::SELECT,
1032 - 'options' => [
1033 - '' => esc_html__( 'Default', 'uicore-elements' ),
1034 - '100' => '100%',
1035 - '80' => '80%',
1036 - '75' => '75%',
1037 - '70' => '70%',
1038 - '66' => '66%',
1039 - '60' => '60%',
1040 - '50' => '50%',
1041 - '40' => '40%',
1042 - '33' => '33%',
1043 - '30' => '30%',
1044 - '25' => '25%',
1045 - '20' => '20%',
882 + $this->add_responsive_control(
883 + 'button_width',
884 + [
885 + 'label' => esc_html__('Column Width', 'uicore-elements'),
886 + 'type' => Controls_Manager::SELECT,
887 + 'options' => [
888 + '' => esc_html__('Default', 'uicore-elements'),
889 + '100' => '100%',
890 + '80' => '80%',
891 + '75' => '75%',
892 + '70' => '70%',
893 + '66' => '66%',
894 + '60' => '60%',
895 + '50' => '50%',
896 + '40' => '40%',
897 + '33' => '33%',
898 + '30' => '30%',
899 + '25' => '25%',
900 + '20' => '20%',
901 + ],
902 + 'default' => '100',
903 + ]
904 + );
905 + $this->add_responsive_control(
906 + 'button_align',
907 + [
908 + 'label' => esc_html__('Alignment', 'uicore-elements'),
909 + 'type' => Controls_Manager::CHOOSE,
910 + 'options' => [
911 + 'left' => [
912 + 'title' => esc_html__('Left', 'uicore-elements'),
913 + 'icon' => 'eicon-text-align-left',
1046 914 ],
1047 - 'default' => '100',
1048 - ]
1049 - );
1050 - $this->add_responsive_control(
1051 - 'button_align',
1052 - [
1053 - 'label' => esc_html__( 'Alignment', 'uicore-elements' ),
1054 - 'type' => Controls_Manager::CHOOSE,
1055 - 'options' => [
1056 - 'left' => [
1057 - 'title' => esc_html__( 'Left', 'uicore-elements' ),
1058 - 'icon' => 'eicon-text-align-left',
1059 - ],
1060 - 'center' => [
1061 - 'title' => esc_html__( 'Center', 'uicore-elements' ),
1062 - 'icon' => 'eicon-text-align-center',
1063 - ],
1064 - 'right' => [
1065 - 'title' => esc_html__( 'Right', 'uicore-elements' ),
1066 - 'icon' => 'eicon-text-align-right',
1067 - ],
1068 - 'stretch' => [
1069 - 'title' => esc_html__( 'Justified', 'uicore-elements' ),
1070 - 'icon' => 'eicon-text-align-justify',
1071 - ],
915 + 'center' => [
916 + 'title' => esc_html__('Center', 'uicore-elements'),
917 + 'icon' => 'eicon-text-align-center',
1072 918 ],
1073 - 'default' => 'stretch',
1074 - 'prefix_class' => 'ui-e-submit-align-',
1075 - ]
1076 - );
1077 - $this->add_control(
1078 - 'button_text',
1079 - [
1080 - 'label' => esc_html__( 'Submit', 'uicore-elements' ),
1081 - 'type' => Controls_Manager::TEXT,
1082 - 'default' => esc_html__( 'Send', 'uicore-elements' ),
1083 - 'placeholder' => esc_html__( 'Send', 'uicore-elements' ),
1084 - 'dynamic' => [
1085 - 'active' => true,
919 + 'right' => [
920 + 'title' => esc_html__('Right', 'uicore-elements'),
921 + 'icon' => 'eicon-text-align-right',
1086 922 ],
1087 - 'ai' => [
1088 - 'active' => false,
923 + 'stretch' => [
924 + 'title' => esc_html__('Justified', 'uicore-elements'),
925 + 'icon' => 'eicon-text-align-justify',
1089 926 ],
1090 - ]
1091 - );
1092 - $this->add_control(
1093 - 'selected_button_icon',
1094 - [
1095 - 'label' => esc_html__( 'Icon', 'uicore-elements' ),
1096 - 'type' => Controls_Manager::ICONS,
1097 - 'skin' => 'inline',
1098 - 'label_block' => false,
1099 - ]
1100 - );
1101 - $this->add_control(
1102 - 'button_icon_align',
1103 - [
1104 - 'label' => esc_html__( 'Icon Position', 'uicore-elements' ),
1105 - 'type' => Controls_Manager::SELECT,
1106 - 'default' => 'left',
1107 - 'options' => [
1108 - 'left' => esc_html__( 'Before', 'uicore-elements' ),
1109 - 'right' => esc_html__( 'After', 'uicore-elements' ),
927 + ],
928 + 'default' => 'stretch',
929 + 'prefix_class' => 'ui-e-submit-align-%s-',
930 + ]
931 + );
932 + $this->add_control(
933 + 'button_text',
934 + [
935 + 'label' => esc_html__('Submit', 'uicore-elements'),
936 + 'type' => Controls_Manager::TEXT,
937 + 'default' => esc_html__('Send', 'uicore-elements'),
938 + 'placeholder' => esc_html__('Send', 'uicore-elements'),
939 + 'dynamic' => [
940 + 'active' => true,
941 + ],
942 + 'ai' => [
943 + 'active' => false,
944 + ],
945 + ]
946 + );
947 + $this->add_control(
948 + 'selected_button_icon',
949 + [
950 + 'label' => esc_html__('Icon', 'uicore-elements'),
951 + 'type' => Controls_Manager::ICONS,
952 + 'skin' => 'inline',
953 + 'label_block' => false,
954 + ]
955 + );
956 + $this->add_control(
957 + 'button_icon_align',
958 + [
959 + 'label' => esc_html__('Icon Position', 'uicore-elements'),
960 + 'type' => Controls_Manager::SELECT,
961 + 'default' => 'left',
962 + 'options' => [
963 + 'left' => esc_html__('Before', 'uicore-elements'),
964 + 'right' => esc_html__('After', 'uicore-elements'),
965 + ],
966 + 'condition' => [
967 + 'selected_button_icon[value]!' => '',
968 + ],
969 + ]
970 + );
971 + $this->add_control(
972 + 'button_icon_indent',
973 + [
974 + 'label' => esc_html__('Icon Spacing', 'uicore-elements'),
975 + 'type' => Controls_Manager::SLIDER,
976 + 'size_units' => ['px', 'em', 'rem', 'custom'],
977 + 'range' => [
978 + 'px' => [
979 + 'max' => 100,
1110 980 ],
1111 - 'condition' => [
1112 - 'selected_button_icon[value]!' => '',
981 + 'em' => [
982 + 'max' => 10,
1113 983 ],
1114 - ]
1115 - );
1116 - $this->add_control(
1117 - 'button_icon_indent',
1118 - [
1119 - 'label' => esc_html__( 'Icon Spacing', 'uicore-elements' ),
1120 - 'type' => Controls_Manager::SLIDER,
1121 - 'size_units' => [ 'px', 'em', 'rem', 'custom' ],
1122 - 'range' => [
1123 - 'px' => [
1124 - 'max' => 100,
1125 - ],
1126 - 'em' => [
1127 - 'max' => 10,
1128 - ],
1129 - 'rem' => [
1130 - 'max' => 10,
1131 - ],
984 + 'rem' => [
985 + 'max' => 10,
1132 986 ],
1133 - 'condition' => [
1134 - 'selected_button_icon[value]!' => '',
1135 - ],
1136 - 'selectors' => [
1137 - '{{WRAPPER}} .elementor-button .ui-e-align-right' => 'margin-left: {{SIZE}}{{UNIT}};',
1138 - '{{WRAPPER}} .elementor-button .ui-e-align-left' => 'margin-right: {{SIZE}}{{UNIT}};',
1139 - ],
1140 - ]
1141 - );
1142 - $this->add_control(
1143 - 'button_css_id',
1144 - [
1145 - 'label' => esc_html__( 'Button ID', 'uicore-elements' ),
1146 - 'type' => Controls_Manager::TEXT,
1147 - 'default' => '',
1148 - 'ai' => [
1149 - 'active' => false,
1150 - ],
1151 - 'title' => esc_html__( 'Add your custom id WITHOUT the Pound key. e.g: my-id', 'uicore-elements' ),
1152 - 'description' => esc_html__( 'Please make sure the ID is unique and not used elsewhere on the page this form is displayed. This field allows `A-z 0-9` & underscore chars without spaces.', 'uicore-elements' ),
1153 - 'separator' => 'before',
1154 - 'dynamic' => [
1155 - 'active' => true,
1156 - ],
1157 - ]
1158 - );
1159 -
1160 -
1161 - $this->end_controls_section();
1162 -
1163 - $this->start_controls_section(
1164 - 'section_actions',
987 + ],
988 + 'condition' => [
989 + 'selected_button_icon[value]!' => '',
990 + ],
991 + 'selectors' => [
992 + '{{WRAPPER}} .elementor-button .ui-e-align-right' => 'margin-left: {{SIZE}}{{UNIT}};',
993 + '{{WRAPPER}} .elementor-button .ui-e-align-left' => 'margin-right: {{SIZE}}{{UNIT}};',
994 + ],
995 + ]
996 + );
997 + $this->add_control(
998 + 'button_css_id',
1165 999 [
1166 - 'label' => esc_html__( 'Actions After Submit', 'uicore-elements' ),
1000 + 'label' => esc_html__('Button ID', 'uicore-elements'),
1001 + 'type' => Controls_Manager::TEXT,
1002 + 'default' => '',
1003 + 'ai' => [
1004 + 'active' => false,
1005 + ],
1006 + 'title' => esc_html__('Add your custom id WITHOUT the Pound key. e.g: my-id', 'uicore-elements'),
1007 + 'description' => esc_html__('Please make sure the ID is unique and not used elsewhere on the page this form is displayed. This field allows `A-z 0-9` & underscore chars without spaces.', 'uicore-elements'),
1008 + 'separator' => 'before',
1009 + 'dynamic' => [
1010 + 'active' => true,
1011 + ],
1167 1012 ]
1168 1013 );
1169 1014
1170 - $this->add_control(
1171 - 'submit_actions',
1172 - [
1173 - 'label' => esc_html__( 'Submit Actions', 'uicore-elements' ),
1174 - 'type' => Controls_Manager::SELECT2,
1175 - 'label_block' => true,
1176 - 'multiple' => true,
1177 - 'options' => [
1178 - 'email' => esc_html__( 'Email', 'uicore-elements' ),
1179 - 'email_2' => esc_html__( 'Email 2', 'uicore-elements' ),
1180 - 'redirect' => esc_html__( 'Redirect', 'uicore-elements' ),
1181 - 'mailchimp' => esc_html__( 'MailChimp', 'uicore-elements' ),
1182 - ],
1183 - 'default' => [ 'email' ],
1184 - ]
1185 - );
1186 1015
1187 1016 $this->end_controls_section();
1188 1017
1018 + $this->TRAIT_register_submit_actions_controls(Contact_Form_Service::get_form_submit_options());
1019 +
1189 1020 // Submit sections
1190 1021 $this->start_controls_section(
1191 1022 'section_email',
1192 1023 [
1193 - 'label' => esc_html__( 'Email', 'uicore-elements' ),
1024 + 'label' => esc_html__('Email', 'uicore-elements'),
1194 1025 'condition' => [
1195 1026 'submit_actions' => 'email',
1196 1027 ],
1197 1028 ]
@@ -1196,9 +1027,9 @@
1196 1027 ],
1197 1028 ]
1198 1029 );
1199 1030
1200 - $this->register_submit_email_controls($this);
1031 + $this->TRAIT_register_submit_email_controls($this);
1201 1032
1202 1033 $this->end_controls_section();
1203 1034
1204 1035 $this->start_controls_section(
@@ -1203,9 +1034,9 @@
1203 1034
1204 1035 $this->start_controls_section(
1205 1036 'section_email_2',
1206 1037 [
1207 - 'label' => esc_html__( 'Email 2', 'uicore-elements' ),
1038 + 'label' => esc_html__('Email 2', 'uicore-elements'),
1208 1039 'condition' => [
1209 1040 'submit_actions' => 'email_2',
1210 1041 ],
1211 1042 ]
@@ -1210,969 +1041,291 @@
1210 1041 ],
1211 1042 ]
1212 1043 );
1213 1044
1214 - $this->register_submit_email_controls($this, '_2');
1045 + $this->TRAIT_register_submit_email_controls($this, '_2');
1215 1046
1216 1047 $this->end_controls_section();
1217 1048
1218 - $this->start_controls_section(
1219 - 'section_redirect',
1049 + $this->TRAIT_register_submit_redirect_controls();
1050 + $this->TRAIT_register_submit_popup_controls($this);
1051 + $this->TRAIT_register_submit_webhook_controls();
1052 + $this->TRAIT_register_submit_newsletter_services_controls(Newsletter_Services::get_services_list('keys'), true);
1053 + $default_messages = Contact_Form_Service::get_default_messages();
1054 + $this->TRAIT_register_additional_controls($default_messages);
1055 +
1056 + $this->TRAIT_register_all_form_style_controls();
1057 +
1058 + // Custom Fields additional Controls injection
1059 + $this->start_injection([
1060 + 'of' => 'redirect_message',
1061 + 'at' => 'before',
1062 + ]);
1063 + $this->add_control(
1064 + 'required_fields_message',
1220 1065 [
1221 - 'label' => esc_html__( 'Redirect', 'uicore-elements' ),
1222 - 'condition' => [
1223 - 'submit_actions' => 'redirect',
1066 + 'label' => esc_html__('Required Fields', 'uicore-elements'),
1067 + 'type' => Controls_Manager::TEXT,
1068 + 'default' => $default_messages['required'],
1069 + 'placeholder' => $default_messages['required'],
1070 + 'label_block' => true,
1071 + 'conditions' => [
1072 + 'terms' => [
1073 + [
1074 + 'name' => 'custom_messages',
1075 + 'operator' => '!=',
1076 + 'value' => '',
1077 + ],
1078 + ],
1224 1079 ],
1080 + 'render_type' => 'none',
1081 + 'dynamic' => [
1082 + 'active' => true,
1083 + ],
1225 1084 ]
1226 1085 );
1086 + $this->end_injection();
1227 1087
1228 - $this->add_control(
1229 - 'redirect_to',
1230 - [
1231 - 'label' => esc_html__( 'Redirect To', 'uicore-elements' ),
1232 - 'type' => Controls_Manager::TEXT,
1233 - 'placeholder' => esc_html__( 'https://your-link.com', 'uicore-elements' ),
1234 - 'ai' => [
1235 - 'active' => false,
1088 + // Specific Form style controls
1089 + $this->start_injection([
1090 + 'of' => 'form_styles_component_divider',
1091 + 'at' => 'after',
1092 + ]);
1093 +
1094 + $this->add_control(
1095 + 'heading_html',
1096 + [
1097 + 'label' => esc_html__('HTML Field', 'uicore-elements'),
1098 + 'type' => Controls_Manager::HEADING,
1099 + ]
1100 + );
1101 + $this->add_control(
1102 + 'html_spacing',
1103 + [
1104 + 'label' => esc_html__('Spacing', 'uicore-elements'),
1105 + 'type' => Controls_Manager::SLIDER,
1106 + 'size_units' => ['px', 'em', 'rem', 'custom'],
1107 + 'default' => [
1108 + 'size' => 0,
1109 + ],
1110 + 'range' => [
1111 + 'px' => [
1112 + 'max' => 60,
1236 1113 ],
1237 - 'dynamic' => [
1238 - 'active' => true,
1239 - 'categories' => [
1240 - 'url',
1241 - ],
1114 + 'em' => [
1115 + 'max' => 6,
1242 1116 ],
1243 - 'label_block' => true,
1244 - 'render_type' => 'none',
1245 - ]
1246 - );
1247 -
1248 - $this->end_controls_section();
1249 -
1250 - $this->start_controls_section(
1251 - 'mailchimp_redirect',
1117 + 'rem' => [
1118 + 'max' => 6,
1119 + ],
1120 + ],
1121 + 'selectors' => [
1122 + '{{WRAPPER}} .ui-e-field-type-html' => 'padding-bottom: {{SIZE}}{{UNIT}};',
1123 + ],
1124 + ]
1125 + );
1126 + $this->add_control(
1127 + 'html_color',
1252 1128 [
1253 - 'label' => esc_html__( 'Mailchimp', 'uicore-elements' ),
1254 - 'condition' => [
1255 - 'submit_actions' => 'mailchimp',
1129 + 'label' => esc_html__('Color', 'uicore-elements'),
1130 + 'type' => Controls_Manager::COLOR,
1131 + 'selectors' => [
1132 + '{{WRAPPER}} .ui-e-field-type-html' => 'color: {{VALUE}};',
1256 1133 ],
1257 1134 ]
1258 1135 );
1136 + $this->add_group_control(
1137 + Group_Control_Typography::get_type(),
1138 + [
1139 + 'name' => 'html_typography',
1140 + 'selector' => '{{WRAPPER}} .ui-e-field-type-html',
1141 + 'global' => [
1142 + 'default' => Global_Typography::TYPOGRAPHY_TEXT,
1143 + ],
1144 + ]
1145 + );
1259 1146
1260 - $this->TRAIT_register_submit_mailchimp_controls($this, true);
1261 -
1262 - $this->end_controls_section();
1263 -
1264 - $default_messages = Contact_Form_Service::get_default_messages();
1265 - $this->start_controls_section(
1266 - 'section_form_options',
1147 + $this->add_control(
1148 + 'heading_file',
1267 1149 [
1268 - 'label' => esc_html__( 'Additional Options', 'uicore-elements' ),
1269 - 'tab' => Controls_Manager::TAB_CONTENT,
1150 + 'label' => esc_html__('Upload File Field', 'uicore-elements'),
1151 + 'type' => Controls_Manager::HEADING,
1152 + 'separator' => 'before',
1270 1153 ]
1271 1154 );
1155 + $this->add_control(
1156 + 'file_color',
1157 + [
1158 + 'label' => esc_html__('Color', 'uicore-elements'),
1159 + 'type' => Controls_Manager::COLOR,
1160 + 'selectors' => [
1161 + '{{WRAPPER}} .ui-e-field-type-file input.ui-e-field' => 'color: {{VALUE}};',
1162 + ],
1163 + 'default' => 'var(--e-global-color-uicore_body)',
1272 1164
1273 - $this->add_control(
1274 - 'form_id',
1275 - [
1276 - 'label' => esc_html__( 'Form ID', 'uicore-elements' ),
1277 - 'type' => Controls_Manager::TEXT,
1278 - 'ai' => [
1279 - 'active' => false,
1280 - ],
1281 - 'placeholder' => 'new_form_id',
1282 - 'description' => esc_html__( 'Please make sure the ID is unique and not used elsewhere on the page this form is displayed. This field allows `A-z 0-9` & underscore chars without spaces.', 'uicore-elements' ),
1283 - 'separator' => 'after',
1284 - 'dynamic' => [
1285 - 'active' => true,
1286 - ],
1287 - ]
1288 - );
1289 - $this->add_control(
1290 - 'form_validation',
1291 - [
1292 - 'label' => esc_html__( 'Form Validation', 'uicore-elements' ),
1293 - 'type' => Controls_Manager::SELECT,
1294 - 'options' => [
1295 - '' => esc_html__( 'Browser Default', 'uicore-elements' ),
1296 - 'no' => esc_html__( 'No validation', 'uicore-elements' ),
1297 - ],
1298 - 'default' => '',
1299 - ]
1300 - );
1301 - $this->add_control(
1302 - 'custom_messages',
1303 - [
1304 - 'label' => esc_html__( 'Custom Messages', 'uicore-elements' ),
1305 - 'type' => Controls_Manager::SWITCHER,
1306 - 'default' => '',
1307 - 'separator' => 'before',
1308 - 'render_type' => 'none',
1309 - ]
1310 - );
1311 - $this->add_control(
1312 - 'success_message',
1313 - [
1314 - 'label' => esc_html__( 'Success Message', 'uicore-elements' ),
1315 - 'type' => Controls_Manager::TEXT,
1316 - 'default' => $default_messages['success'],
1317 - 'placeholder' => $default_messages['success'],
1318 - 'label_block' => true,
1319 - 'condition' => [
1320 - 'custom_messages!' => '',
1321 - ],
1322 - 'render_type' => 'none',
1323 - 'dynamic' => [
1324 - 'active' => true,
1325 - ],
1326 - ]
1327 - );
1328 - $this->add_control(
1329 - 'error_message',
1330 - [
1331 - 'label' => esc_html__( 'Form Error', 'uicore-elements' ),
1332 - 'type' => Controls_Manager::TEXT,
1333 - 'default' => $default_messages['error'],
1334 - 'placeholder' => $default_messages['error'],
1335 - 'label_block' => true,
1336 - 'condition' => [
1337 - 'custom_messages!' => '',
1338 - ],
1339 - 'render_type' => 'none',
1340 - 'dynamic' => [
1341 - 'active' => true,
1342 - ],
1343 - ]
1344 - );
1345 - $this->add_control(
1346 - 'mail_error_message',
1347 - [
1348 - 'label' => esc_html__( 'Email Sending Error', 'uicore-elements' ),
1349 - 'type' => Controls_Manager::TEXT,
1350 - 'default' => $default_messages['mail_error'],
1351 - 'placeholder' => $default_messages['mail_error'],
1352 - 'label_block' => true,
1353 - 'condition' => [
1354 - 'custom_messages!' => '',
1355 - ],
1356 - 'render_type' => 'none',
1357 - 'dynamic' => [
1358 - 'active' => true,
1359 - ],
1360 - ]
1361 - );
1362 - $this->add_control(
1363 - 'redirect_message',
1364 - [
1365 - 'label' => esc_html__( 'Sucessfull Redirect', 'uicore-elements' ),
1366 - 'type' => Controls_Manager::TEXT,
1367 - 'default' => $default_messages['redirect'],
1368 - 'placeholder' => $default_messages['redirect'],
1369 - 'label_block' => true,
1370 - 'conditions' => [
1371 - 'terms' => [
1372 - [
1373 - 'name' => 'custom_messages',
1374 - 'operator' => '!=',
1375 - 'value' => '',
1376 - ],
1377 - [
1378 - 'name' => 'submit_actions',
1379 - 'operator' => 'contains',
1380 - 'value' => 'redirect',
1381 - ]
1382 - ],
1383 - ],
1384 - 'render_type' => 'none',
1385 - 'dynamic' => [
1386 - 'active' => true,
1387 - ],
1388 - ]
1389 - );
1390 -
1391 - $this->end_controls_section();
1392 -
1393 - $this->start_controls_section(
1394 - 'section_form_style',
1395 - [
1396 - 'label' => esc_html__( 'Form', 'uicore-elements' ),
1397 - 'tab' => Controls_Manager::TAB_STYLE,
1398 - ]
1399 - );
1400 -
1401 - $this->add_control(
1402 - 'column_gap',
1403 - [
1404 - 'label' => esc_html__( 'Columns Gap', 'uicore-elements' ),
1405 - 'type' => Controls_Manager::SLIDER,
1406 - 'size_units' => [ 'px', 'em', 'rem', 'custom' ],
1407 - 'default' => [
1408 - 'size' => 10,
1409 - ],
1410 - 'range' => [
1411 - 'px' => [
1412 - 'max' => 60,
1413 - ],
1414 - 'em' => [
1415 - 'max' => 6,
1416 - ],
1417 - 'rem' => [
1418 - 'max' => 6,
1419 - ],
1420 - ],
1421 - 'selectors' => [
1422 - '{{WRAPPER}} .ui-e-field-group' => 'padding-right: calc( {{SIZE}}{{UNIT}}/2 ); padding-left: calc( {{SIZE}}{{UNIT}}/2 );',
1423 - '{{WRAPPER}} .ui-e-fields-wrp' => 'margin-left: calc( -{{SIZE}}{{UNIT}}/2 ); margin-right: calc( -{{SIZE}}{{UNIT}}/2 );',
1424 - ],
1425 - ]
1426 - );
1427 - $this->add_control(
1428 - 'row_gap',
1429 - [
1430 - 'label' => esc_html__( 'Rows Gap', 'uicore-elements' ),
1431 - 'type' => Controls_Manager::SLIDER,
1432 - 'size_units' => [ 'px', 'em', 'rem', 'custom' ],
1433 - 'default' => [
1434 - 'size' => 10,
1435 - ],
1436 - 'range' => [
1437 - 'px' => [
1438 - 'max' => 60,
1439 - ],
1440 - 'em' => [
1441 - 'max' => 6,
1442 - ],
1443 - 'rem' => [
1444 - 'max' => 6,
1445 - ],
1446 - ],
1447 - 'selectors' => [
1448 - '{{WRAPPER}} .ui-e-field-group' => 'margin-bottom: {{SIZE}}{{UNIT}};',
1449 - '{{WRAPPER}} .ui-e-fields-wrp' => 'margin-bottom: -{{SIZE}}{{UNIT}};',
1450 - ],
1451 - ]
1452 - );
1453 - $this->add_control(
1454 - 'heading_label',
1455 - [
1456 - 'label' => esc_html__( 'Label', 'uicore-elements' ),
1457 - 'type' => Controls_Manager::HEADING,
1458 - 'separator' => 'before',
1459 - ]
1460 - );
1461 - $this->add_control(
1462 - 'label_spacing',
1463 - [
1464 - 'label' => esc_html__( 'Spacing', 'uicore-elements' ),
1465 - 'type' => Controls_Manager::SLIDER,
1466 - 'size_units' => [ 'px', 'em', 'rem', 'custom' ],
1467 - 'default' => [
1468 - 'size' => 0,
1469 - ],
1470 - 'range' => [
1471 - 'px' => [
1472 - 'max' => 60,
1473 - ],
1474 - 'em' => [
1475 - 'max' => 6,
1476 - ],
1477 - 'rem' => [
1478 - 'max' => 6,
1479 - ],
1480 - ],
1481 - 'selectors' => [
1482 - 'body {{WRAPPER}} .ui-e-field-group > label' => 'padding-bottom: {{SIZE}}{{UNIT}};',
1483 - ],
1484 - ]
1485 - );
1486 - $this->add_control(
1487 - 'label_color',
1488 - [
1489 - 'label' => esc_html__( 'Text Color', 'uicore-elements' ),
1490 - 'type' => Controls_Manager::COLOR,
1491 - 'selectors' => [
1492 - '{{WRAPPER}} .ui-e-field-group > label, {{WRAPPER}} .ui-e-field-subgroup label' => 'color: {{VALUE}};',
1493 - ],
1494 - 'global' => [
1495 - 'default' => Global_Colors::COLOR_TEXT,
1496 - ],
1497 - ]
1498 - );
1499 - $this->add_control(
1500 - 'mark_required_color',
1501 - [
1502 - 'label' => esc_html__( 'Mark Color', 'uicore-elements' ),
1503 - 'type' => Controls_Manager::COLOR,
1504 - 'default' => '',
1505 - 'selectors' => [
1506 - '{{WRAPPER}} .ui-e-required .ui-e-label:after' => 'color: {{COLOR}};',
1507 - ],
1508 - 'condition' => [
1509 - 'mark_required' => 'yes',
1510 - ],
1511 - ]
1512 - );
1513 - $this->add_group_control(
1514 - Group_Control_Typography::get_type(),
1515 - [
1516 - 'name' => 'label_typography',
1517 - 'selector' => '{{WRAPPER}} .ui-e-field-group > label',
1518 - 'global' => [
1519 - 'default' => Global_Typography::TYPOGRAPHY_TEXT,
1520 - ],
1521 - ]
1522 - );
1523 - $this->add_control(
1524 - 'heading_html',
1525 - [
1526 - 'label' => esc_html__( 'HTML Field', 'uicore-elements' ),
1527 - 'type' => Controls_Manager::HEADING,
1528 - 'separator' => 'before',
1529 - ]
1530 - );
1531 - $this->add_control(
1532 - 'html_spacing',
1533 - [
1534 - 'label' => esc_html__( 'Spacing', 'uicore-elements' ),
1535 - 'type' => Controls_Manager::SLIDER,
1536 - 'size_units' => [ 'px', 'em', 'rem', 'custom' ],
1537 - 'default' => [
1538 - 'size' => 0,
1539 - ],
1540 - 'range' => [
1541 - 'px' => [
1542 - 'max' => 60,
1543 - ],
1544 - 'em' => [
1545 - 'max' => 6,
1546 - ],
1547 - 'rem' => [
1548 - 'max' => 6,
1549 - ],
1550 - ],
1551 - 'selectors' => [
1552 - '{{WRAPPER}} .ui-e-field-type-html' => 'padding-bottom: {{SIZE}}{{UNIT}};',
1553 - ],
1554 - ]
1555 - );
1556 - $this->add_control(
1557 - 'html_color',
1558 - [
1559 - 'label' => esc_html__( 'Color', 'uicore-elements' ),
1560 - 'type' => Controls_Manager::COLOR,
1561 - 'selectors' => [
1562 - '{{WRAPPER}} .ui-e-field-type-html' => 'color: {{VALUE}};',
1563 - ],
1564 - 'global' => [
1565 - 'default' => Global_Colors::COLOR_TEXT,
1566 - ],
1567 - ]
1568 - );
1569 - $this->add_group_control(
1570 - Group_Control_Typography::get_type(),
1571 - [
1572 - 'name' => 'html_typography',
1573 - 'selector' => '{{WRAPPER}} .ui-e-field-type-html',
1574 - 'global' => [
1575 - 'default' => Global_Typography::TYPOGRAPHY_TEXT,
1576 - ],
1577 - ]
1578 - );
1579 -
1580 - $this->end_controls_section();
1581 -
1582 - $this->start_controls_section(
1583 - 'section_field_style',
1584 - [
1585 - 'label' => esc_html__( 'Fields', 'uicore-elements' ),
1586 - 'tab' => Controls_Manager::TAB_STYLE,
1587 - ]
1588 - );
1589 -
1590 - $this->start_controls_tabs(
1591 - 'field_style_tabs'
1592 - );
1593 -
1594 - $this->start_controls_tab(
1595 - 'field_normal_tab',
1596 - [
1597 - 'label' => esc_html__( 'Normal', 'uicore-elements' ),
1598 - ]
1599 - );
1600 -
1601 - $this->add_group_control(
1602 - Group_Control_Typography::get_type(),
1603 - [
1604 - 'name' => 'field_typography',
1605 - 'selector' => '{{WRAPPER}} .ui-e-field-group .ui-e-field, {{WRAPPER}} .ui-e-field-subgroup label',
1606 - 'global' => [
1607 - 'default' => Global_Typography::TYPOGRAPHY_TEXT,
1608 - ],
1609 - ]
1610 - );
1611 - $this->add_control(
1612 - 'field_text_color',
1613 - [
1614 - 'label' => esc_html__( 'Text Color', 'uicore-elements' ),
1615 - 'type' => Controls_Manager::COLOR,
1616 - 'selectors' => [
1617 - '{{WRAPPER}} .ui-e-field-group .ui-e-field' => 'color: {{VALUE}};',
1618 - ],
1619 - 'global' => [
1620 - 'default' => Global_Colors::COLOR_TEXT,
1621 - ],
1622 - ]
1623 - );
1624 - $this->add_control(
1625 - 'field_placeholder_color',
1626 - [
1627 - 'label' => esc_html__( 'Placeholder Color', 'uicore-elements' ),
1628 - 'type' => Controls_Manager::COLOR,
1629 - 'selectors' => [
1630 - '{{WRAPPER}} .ui-e-field-group .ui-e-field::placeholder' => 'color: {{VALUE}};',
1631 - ],
1632 - 'global' => [
1633 - 'default' => Global_Colors::COLOR_TEXT,
1634 - ],
1635 - ]
1636 - );
1637 - $this->add_control(
1638 - 'field_background_color',
1639 - [
1640 - 'label' => esc_html__( 'Background Color', 'uicore-elements' ),
1641 - 'type' => Controls_Manager::COLOR,
1642 - 'default' => '#ffffff',
1643 - 'selectors' => [
1644 - '{{WRAPPER}} .ui-e-field-group:not(.ui-e-field-type-file) .ui-e-field:not(.ui-e-field-select)' => 'background-color: {{VALUE}};',
1645 - '{{WRAPPER}} .ui-e-field-group .ui-e-field-select select' => 'background-color: {{VALUE}};',
1646 - ],
1647 - ]
1648 - );
1649 - $this->add_group_control(
1650 - Group_Control_Border::get_type(),
1651 - [
1652 - 'name' => 'field_border',
1653 - 'selector' =>
1654 - '{{WRAPPER}} .ui-e-field-group:not(.ui-e-field-type-file) .ui-e-field:not(.ui-e-field-select),
1655 - {{WRAPPER}} .ui-e-field-group .ui-e-field-select select',
1656 - ]
1657 - );
1658 -
1659 - $this->end_controls_tab();
1660 -
1661 - $this->start_controls_tab(
1662 - 'field_hover_tab',
1663 - [
1664 - 'label' => esc_html__( 'Hover', 'uicore-elements' ),
1665 - ]
1666 - );
1667 -
1668 - $this->add_control(
1669 - 'field_text_hover_color',
1670 - [
1671 - 'label' => esc_html__( 'Text Color', 'uicore-elements' ),
1672 - 'type' => Controls_Manager::COLOR,
1673 - 'selectors' => [
1674 - '{{WRAPPER}} .ui-e-field-group:hover .ui-e-field' => 'color: {{VALUE}};',
1675 - ],
1676 - 'global' => [
1677 - 'default' => Global_Colors::COLOR_TEXT,
1678 - ],
1679 - ]
1680 - );
1681 - $this->add_control(
1682 - 'field_placeholder_hover_color',
1683 - [
1684 - 'label' => esc_html__( 'Placeholder Color', 'uicore-elements' ),
1685 - 'type' => Controls_Manager::COLOR,
1686 - 'selectors' => [
1687 - '{{WRAPPER}} .ui-e-field-group:hover .ui-e-field::placeholder' => 'color: {{VALUE}};',
1688 - ],
1689 - 'global' => [
1690 - 'default' => Global_Colors::COLOR_TEXT,
1691 - ],
1692 - ]
1693 - );
1694 - $this->add_control(
1695 - 'field_background_hover_color',
1696 - [
1697 - 'label' => esc_html__( 'Background Color', 'uicore-elements' ),
1698 - 'type' => Controls_Manager::COLOR,
1699 - 'default' => '#ffffff',
1700 - 'selectors' => [
1701 - '{{WRAPPER}} .ui-e-field-group:hover:not(.ui-e-field-type-file) .ui-e-field:not(.ui-e-field-select)' => 'background-color: {{VALUE}};',
1702 - '{{WRAPPER}} .ui-e-field-group:hover .ui-e-field-select select' => 'background-color: {{VALUE}};',
1703 - ],
1704 - ]
1705 - );
1706 - $this->add_group_control(
1707 - Group_Control_Border::get_type(),
1708 - [
1709 - 'name' => 'field_hover_border',
1710 - 'selector' =>
1711 - '{{WRAPPER}} .ui-e-field-group:hover:not(.ui-e-field-type-file) .ui-e-field:not(.ui-e-field-select),
1712 - {{WRAPPER}} .ui-e-field-group:hover .ui-e-field-select select',
1713 - ]
1714 - );
1715 -
1716 - $this->end_controls_tab();
1717 -
1718 - $this->start_controls_tab(
1719 - 'field_active_tab',
1720 - [
1721 - 'label' => esc_html__( 'Active', 'uicore-elements' ),
1722 - ]
1723 - );
1724 -
1725 - $this->add_control(
1726 - 'field_text_active_color',
1727 - [
1728 - 'label' => esc_html__( 'Text Color', 'uicore-elements' ),
1729 - 'type' => Controls_Manager::COLOR,
1730 - 'selectors' => [
1731 - '{{WRAPPER}} .ui-e-field-group .ui-e-field:focus' => 'color: {{VALUE}};',
1732 - ],
1733 - 'global' => [
1734 - 'default' => Global_Colors::COLOR_TEXT,
1735 - ],
1736 - ]
1737 - );
1738 - $this->add_control(
1739 - 'field_background_active_color',
1740 - [
1741 - 'label' => esc_html__( 'Background Color', 'uicore-elements' ),
1742 - 'type' => Controls_Manager::COLOR,
1743 - 'default' => '#ffffff',
1744 - 'selectors' => [
1745 - '{{WRAPPER}} .ui-e-field-group:not(.ui-e-field-type-file) .ui-e-field:focus:not(.ui-e-field-select)' => 'background-color: {{VALUE}};',
1746 - '{{WRAPPER}} .ui-e-field-group .ui-e-field-select:focus select' => 'background-color: {{VALUE}};',
1747 - ],
1748 - ]
1749 - );
1750 - $this->add_group_control(
1751 - Group_Control_Border::get_type(),
1752 - [
1753 - 'name' => 'field_active_border',
1754 - 'selector' =>
1755 - '{{WRAPPER}} .ui-e-field-group:not(.ui-e-field-type-file) .ui-e-field:focus:not(.ui-e-field-select),
1756 - {{WRAPPER}} .ui-e-field-group .ui-e-field-select:focus select',
1757 - ]
1758 - );
1759 -
1760 - $this->end_controls_tab();
1761 -
1762 - $this->end_controls_tabs();
1763 -
1764 - $this->add_control(
1765 - 'field_border_radius',
1766 - [
1767 - 'label' => esc_html__( 'Border Radius', 'uicore-elements' ),
1768 - 'type' => Controls_Manager::DIMENSIONS,
1769 - 'size_units' => [ 'px', '%', 'em', 'rem', 'custom' ],
1770 - 'selectors' => [
1771 - '{{WRAPPER}} .ui-e-field-group:not(.ui-e-field-type-file) .ui-e-field:not(.ui-e-field-select)' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
1772 - '{{WRAPPER}} .ui-e-field-group .ui-e-field-select select' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
1773 - ],
1774 - 'separator' => 'before'
1775 - ]
1776 - );
1777 - $this->add_control(
1778 - 'field_padding',
1779 - [
1780 - 'label' => esc_html__( 'Padding', 'uicore-elements' ),
1781 - 'type' => Controls_Manager::DIMENSIONS,
1782 - 'size_units' => [ 'px', '%', 'em', 'rem', 'custom' ],
1783 - 'selectors' => [
1784 - '{{WRAPPER}} .ui-e-field-group:not(.ui-e-field-type-file) .ui-e-field:not(.ui-e-field-select)' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
1785 - '{{WRAPPER}} .ui-e-field-group .ui-e-field-select select' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
1786 - ],
1787 - ]
1788 - );
1789 -
1790 - $this->end_controls_section();
1791 -
1792 - $this->start_controls_section(
1793 - 'section_button_style',
1794 - [
1795 - 'label' => esc_html__( 'Button', 'uicore-elements' ),
1796 - 'tab' => Controls_Manager::TAB_STYLE,
1797 - ]
1798 - );
1799 -
1800 - $this->add_group_control(
1801 - Group_Control_Typography::get_type(),
1802 - [
1803 - 'name' => 'button_typography',
1804 - 'global' => [
1805 - 'default' => Global_Typography::TYPOGRAPHY_ACCENT,
1806 - ],
1807 - 'selector' => '{{WRAPPER}} .elementor-button',
1808 - ]
1809 - );
1810 - $this->add_group_control(
1811 - Group_Control_Border::get_type(), [
1812 - 'name' => 'button_border',
1813 - 'selector' => '{{WRAPPER}} .elementor-button',
1814 - 'exclude' => [
1815 - 'color',
1816 - ],
1817 - ]
1818 - );
1819 -
1820 - $this->start_controls_tabs( 'tabs_button_style' );
1821 -
1822 - $this->start_controls_tab(
1823 - 'tab_button_normal',
1824 - [
1825 - 'label' => esc_html__( 'Normal', 'uicore-elements' ),
1826 - ]
1827 - );
1828 -
1829 - $this->add_control(
1830 - 'button_background_color',
1831 - [
1832 - 'label' => esc_html__( 'Background Color', 'uicore-elements' ),
1833 - 'type' => Controls_Manager::COLOR,
1834 - 'global' => [
1835 - 'default' => Global_Colors::COLOR_ACCENT,
1836 - ],
1837 - 'selectors' => [
1838 - '{{WRAPPER}} .e-form__buttons__wrapper__button-next' => 'background-color: {{VALUE}};',
1839 - '{{WRAPPER}} .elementor-button[type="submit"]' => 'background-color: {{VALUE}};',
1840 - ],
1841 - ]
1842 - );
1843 - $this->add_control(
1844 - 'button_text_color',
1845 - [
1846 - 'label' => esc_html__( 'Text Color', 'uicore-elements' ),
1847 - 'type' => Controls_Manager::COLOR,
1848 - 'default' => '#ffffff',
1849 - 'selectors' => [
1850 - '{{WRAPPER}} .e-form__buttons__wrapper__button-next' => 'color: {{VALUE}};',
1851 - '{{WRAPPER}} .elementor-button[type="submit"]' => 'color: {{VALUE}};',
1852 - '{{WRAPPER}} .elementor-button[type="submit"] svg *' => 'fill: {{VALUE}};',
1853 - ],
1854 - ]
1855 - );
1856 - $this->add_control(
1857 - 'button_border_color',
1858 - [
1859 - 'label' => esc_html__( 'Border Color', 'uicore-elements' ),
1860 - 'type' => Controls_Manager::COLOR,
1861 - 'default' => '',
1862 - 'selectors' => [
1863 - '{{WRAPPER}} .e-form__buttons__wrapper__button-next' => 'border-color: {{VALUE}};',
1864 - '{{WRAPPER}} .elementor-button[type="submit"]' => 'border-color: {{VALUE}};',
1865 - ],
1866 - 'condition' => [
1867 - 'button_border_border!' => '',
1868 - ],
1869 - ]
1870 - );
1871 -
1872 - $this->end_controls_tab();
1873 -
1874 - $this->start_controls_tab(
1875 - 'tab_button_hover',
1876 - [
1877 - 'label' => esc_html__( 'Hover', 'uicore-elements' ),
1878 - ]
1879 - );
1880 -
1881 - $this->add_control(
1882 - 'button_background_hover_color',
1883 - [
1884 - 'label' => esc_html__( 'Background Color', 'uicore-elements' ),
1885 - 'type' => Controls_Manager::COLOR,
1886 - 'default' => '',
1887 - 'selectors' => [
1888 - '{{WRAPPER}} .e-form__buttons__wrapper__button-next:hover' => 'background-color: {{VALUE}};',
1889 - '{{WRAPPER}} .elementor-button[type="submit"]:hover' => 'background-color: {{VALUE}};',
1890 - ],
1891 - ]
1892 - );
1893 - $this->add_control(
1894 - 'button_hover_color',
1895 - [
1896 - 'label' => esc_html__( 'Text Color', 'uicore-elements' ),
1897 - 'type' => Controls_Manager::COLOR,
1898 - 'default' => '#ffffff',
1899 - 'selectors' => [
1900 - '{{WRAPPER}} .e-form__buttons__wrapper__button-next:hover' => 'color: {{VALUE}};',
1901 - '{{WRAPPER}} .elementor-button[type="submit"]:hover' => 'color: {{VALUE}};',
1902 - '{{WRAPPER}} .elementor-button[type="submit"]:hover svg *' => 'fill: {{VALUE}};',
1903 - ],
1904 - ]
1905 - );
1906 - $this->add_control(
1907 - 'button_hover_border_color',
1908 - [
1909 - 'label' => esc_html__( 'Border Color', 'uicore-elements' ),
1910 - 'type' => Controls_Manager::COLOR,
1911 - 'default' => '',
1912 - 'selectors' => [
1913 - '{{WRAPPER}} .e-form__buttons__wrapper__button-next:hover' => 'border-color: {{VALUE}};',
1914 - '{{WRAPPER}} .elementor-button[type="submit"]:hover' => 'border-color: {{VALUE}};',
1915 - ],
1916 - 'condition' => [
1917 - 'button_border_border!' => '',
1918 - ],
1919 - ]
1920 - );
1921 - $this->add_control(
1922 - 'hover_transition_duration',
1923 - [
1924 - 'label' => esc_html__( 'Transition Duration', 'uicore-elements' ),
1925 - 'type' => Controls_Manager::SLIDER,
1926 - 'size_units' => [ 's', 'ms', 'custom' ],
1927 - 'default' => [
1928 - 'unit' => 'ms',
1929 - ],
1930 - 'selectors' => [
1931 - '{{WRAPPER}} .e-form__buttons__wrapper__button-previous' => 'transition-duration: {{SIZE}}{{UNIT}};',
1932 - '{{WRAPPER}} .e-form__buttons__wrapper__button-next' => 'transition-duration: {{SIZE}}{{UNIT}};',
1933 - '{{WRAPPER}} .elementor-button[type="submit"] svg *' => 'transition-duration: {{SIZE}}{{UNIT}};',
1934 - '{{WRAPPER}} .elementor-button[type="submit"]' => 'transition-duration: {{SIZE}}{{UNIT}};',
1935 - ],
1936 - ]
1937 - );
1938 - $this->add_control(
1939 - 'button_hover_animation',
1940 - [
1941 - 'label' => esc_html__( 'Animation', 'uicore-elements' ),
1942 - 'type' => Controls_Manager::HOVER_ANIMATION,
1943 - ]
1944 - );
1945 -
1946 - $this->end_controls_tab();
1947 -
1948 - $this->end_controls_tabs();
1949 -
1950 - $this->add_control(
1951 - 'button_border_radius',
1952 - [
1953 - 'label' => esc_html__( 'Border Radius', 'uicore-elements' ),
1954 - 'type' => Controls_Manager::DIMENSIONS,
1955 - 'size_units' => [ 'px', '%', 'em', 'rem', 'custom' ],
1956 - 'selectors' => [
1957 - '{{WRAPPER}} .elementor-button' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
1958 - ],
1959 - 'separator' => 'before',
1960 - ]
1961 - );
1962 -
1963 - $this->add_control(
1964 - 'button_text_padding',
1965 - [
1966 - 'label' => esc_html__( 'Text Padding', 'uicore-elements' ),
1967 - 'type' => Controls_Manager::DIMENSIONS,
1968 - 'size_units' => [ 'px', '%', 'em', 'rem', 'custom' ],
1969 - 'selectors' => [
1970 - '{{WRAPPER}} .elementor-button' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
1971 - ],
1972 - ]
1973 - );
1974 -
1975 - $this->end_controls_section();
1976 -
1977 - $this->start_controls_section(
1978 - 'section_messages_style',
1979 - [
1980 - 'label' => esc_html__( 'Messages', 'uicore-elements' ),
1981 - 'tab' => Controls_Manager::TAB_STYLE,
1982 - ]
1983 - );
1984 -
1985 - $this->add_control(
1986 - 'show_messages',
1987 - [
1988 - 'label' => esc_html__( 'Show/Hide messages', 'uicore-elements' ),
1989 - 'type' => Controls_Manager::BUTTON,
1990 - 'separator' => 'before',
1991 - 'text' => esc_html__( 'Toggle', 'uicore-elements' ),
1992 - 'event' => 'ui-e-form-show-messages',
1993 - ]
1994 - );
1995 - $this->add_group_control(
1996 - Group_Control_Typography::get_type(),
1997 - [
1998 - 'name' => 'message_typography',
1999 - 'global' => [
2000 - 'default' => Global_Typography::TYPOGRAPHY_TEXT,
2001 - ],
2002 - 'selector' => '{{WRAPPER}} .ui-e-message',
2003 - ]
2004 - );
2005 - $this->add_control(
2006 - 'success_message_color',
2007 - [
2008 - 'label' => esc_html__( 'Success Message Color', 'uicore-elements' ),
2009 - 'type' => Controls_Manager::COLOR,
2010 - 'default' => '#4CAF50',
2011 - 'selectors' => [
2012 - '{{WRAPPER}} .ui-e-message span.success' => 'color: {{COLOR}};',
2013 - ],
2014 - ]
2015 - );
2016 - $this->add_control(
2017 - 'error_message_color',
2018 - [
2019 - 'label' => esc_html__( 'Error Message Color', 'uicore-elements' ),
2020 - 'type' => Controls_Manager::COLOR,
2021 - 'default' => '#F44336',
2022 - 'selectors' => [
2023 - '{{WRAPPER}} .ui-e-message span.error' => 'color: {{COLOR}};',
2024 - ],
2025 - ]
2026 - );
2027 -
2028 - $this->end_controls_section();
2029 - }
1165 + ]
1166 + );
1167 + $this->end_injection();
1168 + }
2030 1169 function recaptcha_js()
2031 1170 {
2032 - ?>
1171 + ?>
2033 1172 <script>
2034 - window.uicore_elements_recaptcha = '<?php echo get_option('uicore_elements_recaptcha_site_key'); ?>';
1173 + window.uicore_elements_recaptcha = '<?php echo esc_html(get_option('uicore_elements_recaptcha_site_key')); ?>';
2035 1174 </script>
2036 - <?php
1175 + <?php
2037 1176 }
2038 1177
2039 - protected function render() {
1178 + protected function render()
1179 + {
2040 1180
2041 - $instance = $this->get_settings_for_display();
1181 + $instance = $this->get_settings_for_display();
2042 1182 $is_recaptcha_required = false;
2043 1183
1184 + // Save widget settings so form API can retrieve them
1185 + set_transient('ui_e_form_widget_settings_' . $this->get_id(), $instance, DAY_IN_SECONDS);
1186 +
2044 1187 // Render Form Atts
2045 - $this->add_render_attribute(
2046 - [
2047 - 'wrapper' => [
2048 - 'class' => [
2049 - 'ui-e-fields-wrp',
2050 - ],
2051 - ],
2052 - 'submit-group' => [
2053 - 'class' => [
2054 - 'ui-e-field-group',
2055 - 'elementor-column',
2056 - 'ui-e-field-type-submit',
2057 - ],
2058 - ],
2059 - 'button' => [
2060 - 'class' => 'elementor-button',
2061 - ],
2062 - 'icon-align' => [
2063 - 'class' => [
2064 - empty( $instance['button_icon_align'] ) ? '' : 'ui-e-icon ui-e-align-' . $instance['button_icon_align'],
2065 - ],
2066 - ],
2067 - ]
2068 - );
1188 + $this->add_render_attribute(
1189 + [
1190 + 'wrapper' => [
1191 + 'class' => [
1192 + 'ui-e-fields-wrp',
1193 + ],
1194 + ],
1195 + 'submit-group' => [
1196 + 'class' => [
1197 + 'ui-e-field-group',
1198 + 'elementor-column',
1199 + 'ui-e-field-type-submit',
1200 + ],
1201 + ],
1202 + 'button' => [
1203 + 'class' => 'elementor-button',
1204 + ],
1205 + 'icon-align' => [
1206 + 'class' => [
1207 + empty($instance['button_icon_align']) ? '' : 'ui-e-icon ui-e-align-' . $instance['button_icon_align'],
1208 + ],
1209 + ],
1210 + ]
1211 + );
2069 1212
2070 1213 // Fallback for empty control values
2071 - if ( empty( $instance['button_width'] ) ) {
2072 - $instance['button_width'] = '100';
2073 - }
1214 + if (empty($instance['button_width'])) {
1215 + $instance['button_width'] = '100';
1216 + }
2074 1217
2075 - // Button atts
2076 - $this->add_render_attribute( 'submit-group', 'class', 'elementor-col-' . $instance['button_width'] . ' e-form__buttons' );
1218 + // Button atts
1219 + $this->add_render_attribute('submit-group', 'class', 'elementor-col-' . $instance['button_width'] . ' e-form__buttons');
2077 1220
2078 - if ( ! empty( $instance['button_width_tablet'] ) ) {
2079 - $this->add_render_attribute( 'submit-group', 'class', 'elementor-md-' . $instance['button_width_tablet'] );
2080 - }
2081 - if ( ! empty( $instance['button_width_mobile'] ) ) {
2082 - $this->add_render_attribute( 'submit-group', 'class', 'elementor-sm-' . $instance['button_width_mobile'] );
2083 - }
2084 - if ( $instance['button_hover_animation'] ) {
2085 - $this->add_render_attribute( 'button', 'class', 'elementor-animation-' . $instance['button_hover_animation'] );
2086 - }
1221 + if (! empty($instance['button_width_tablet'])) {
1222 + $this->add_render_attribute('submit-group', 'class', 'elementor-md-' . $instance['button_width_tablet']);
1223 + }
1224 + if (! empty($instance['button_width_mobile'])) {
1225 + $this->add_render_attribute('submit-group', 'class', 'elementor-sm-' . $instance['button_width_mobile']);
1226 + }
1227 + if ($instance['button_hover_animation']) {
1228 + $this->add_render_attribute('button', 'class', 'elementor-animation-' . $instance['button_hover_animation']);
1229 + }
2087 1230
2088 - // Form atts
2089 - if ( ! empty( $instance['form_id'] ) ) {
2090 - $this->add_render_attribute( 'form', 'id', $instance['form_id'] );
2091 - }
2092 - if ( ! empty( $instance['form_name'] ) ) {
2093 - $this->add_render_attribute( 'form', 'name', $instance['form_name'] );
2094 - }
2095 - if ( 'no' === $instance['form_validation'] ) {
2096 - $this->add_render_attribute( 'form', 'novalidate' );
2097 - }
2098 - if ( ! empty( $instance['button_css_id'] ) ) {
2099 - $this->add_render_attribute( 'button', 'id', $instance['button_css_id'] );
2100 - }
1231 + // Form atts
1232 + if (! empty($instance['form_id'])) {
1233 + $this->add_render_attribute('form', 'id', $instance['form_id']);
1234 + }
1235 + if (! empty($instance['form_name'])) {
1236 + $this->add_render_attribute('form', 'name', $instance['form_name']);
1237 + }
1238 + if ('no' === $instance['form_validation']) {
1239 + $this->add_render_attribute('form', 'novalidate');
1240 + }
1241 + if (! empty($instance['button_css_id'])) {
1242 + $this->add_render_attribute('button', 'id', $instance['button_css_id']);
1243 + }
2101 1244
2102 - $referer_title = trim( wp_title( '', false ) );
2103 - if ( ! $referer_title && is_home() ) {
2104 - $referer_title = get_option( 'blogname' );
2105 - }
1245 + $referer_title = trim(wp_title('', false));
1246 + if (! $referer_title && is_home()) {
1247 + $referer_title = get_option('blogname');
1248 + }
2106 1249
2107 - ?>
1250 + // Get default messages
1251 + $messages = Contact_Form_Service::get_default_messages();
2108 1252
2109 - <form class="ui-e-form" method="post" <?php $this->print_render_attribute_string( 'form' ); ?>>
1253 + // Set frontend validation message
1254 + $front_msg_required = isset($instance['required_fields_message'])
1255 + ? $instance['required_fields_message']
1256 + : $messages['required'];
1257 + ?>
2110 1258
2111 - <input type="hidden" name="post_id" value="<?php echo esc_attr( get_the_ID()); ?>"/>
1259 + <form class="ui-e-form" method="post" <?php $this->print_render_attribute_string('form'); ?>>
1260 +
1261 + <input type="hidden" name="post_id" value="<?php echo esc_attr(get_the_ID()); ?>" />
2112 1262 <input type="hidden" name="widget_type" value="contact-form">
2113 1263
2114 - <div <?php $this->print_render_attribute_string( 'wrapper' ); ?>>
2115 - <?php
2116 - foreach ( $instance['form_fields'] as $item_index => $item ) :
2117 - $this->form_fields_render_attributes( $item_index, $instance, $item );
1264 + <input type="hidden" name="required_fields_message" value="<?php echo esc_html($front_msg_required); ?>">
2118 1265
2119 - $field_type = $item['field_type'];
1266 + <div <?php $this->print_render_attribute_string('wrapper'); ?>>
2120 1267
2121 - if( $field_type === 'recaptcha' || $field_type === 'recaptcha_v3' ){
1268 + <?php foreach ($instance['form_fields'] as $item_index => $item) :
1269 + $this->form_fields_render_attributes($item_index, $instance, $item);
1270 +
1271 + $field_type = $item['field_type'];
1272 +
1273 + if ($field_type === 'recaptcha' || $field_type === 'recaptcha_v3') {
2122 1274 $is_recaptcha_required = true;
2123 1275 }
2124 1276
2125 - $print_label = ! in_array( $item['field_type'], [ 'hidden', 'html' ], true );
2126 - ?>
1277 + $print_label = ! in_array($item['field_type'], ['hidden', 'html'], true);
1278 + ?>
2127 1279
2128 - <div <?php $this->print_render_attribute_string( 'field-group' . $item_index ); ?>>
2129 - <?php
2130 - // Print label (excepts if recaptcha)
2131 - if ( $print_label && $item['field_label'] && $item['field_type'] !== 'recaptcha' && $item['field_type'] !== 'recaptcha_v3' ){
2132 - ?>
2133 - <label <?php $this->print_render_attribute_string( 'label' . $item_index ); ?>>
2134 - <?php // PHPCS - the variable $item['field_label'] is safe.
2135 - echo $item['field_label']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
2136 - </label>
1280 + <div <?php $this->print_render_attribute_string('field-group' . $item_index); ?>>
1281 + <?php
1282 + // Print label (excepts if recaptcha)
1283 + if ($print_label && $item['field_label'] && $item['field_type'] !== 'recaptcha' && $item['field_type'] !== 'recaptcha_v3') {
1284 + ?>
1285 + <label <?php $this->print_render_attribute_string('label' . $item_index); ?>>
1286 + <?php // PHPCS - the variable $item['field_label'] is safe.
1287 + echo Helper::esc_string($item['field_label']); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1288 + ?>
1289 + </label>
2137 1290 <?php
2138 1291 }
2139 1292
2140 - // Print field
2141 - switch ( $item['field_type'] ) :
2142 - case 'html':
2143 - echo do_shortcode( $item['field_html'] );
2144 - break;
1293 + // Print field
1294 + switch ($item['field_type']):
1295 + case 'html':
1296 + echo wp_kses_post(do_shortcode($item['field_html']));
1297 + break;
2145 1298
2146 - case 'textarea':
2147 - // PHPCS - the method build_textarea_field is safe.
2148 - echo $this->build_textarea_field( $item, $item_index ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2149 - break;
1299 + case 'textarea':
1300 + // PHPCS - the method build_textarea_field is safe.
1301 + echo $this->build_textarea_field($item, $item_index); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1302 + break;
2150 1303
2151 - case 'select':
2152 - // PHPCS - the method build_select_field is safe.
2153 - echo $this->build_select_field( $item, $item_index ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2154 - break;
1304 + case 'select':
1305 + // PHPCS - the method build_select_field is safe.
1306 + echo $this->build_select_field($item, $item_index); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1307 + break;
2155 1308
2156 - case 'acceptance':
2157 - // PHPCS - the method build_select_field is safe.
2158 - echo $this->build_acceptance_field( $item, $item_index); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2159 - break;
1309 + case 'acceptance':
1310 + // PHPCS - the method build_select_field is safe.
1311 + $this->build_acceptance_field($item, $item_index); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1312 + break;
2160 1313
2161 - case 'radio':
2162 - case 'checkbox':
2163 - // PHPCS - the method build_radio_checkbox_field is safe.
2164 - echo $this->build_radio_checkbox_field( $item, $item_index, $item['field_type'] ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2165 - break;
1314 + case 'radio':
1315 + case 'checkbox':
1316 + // PHPCS - the method build_radio_checkbox_field is safe.
1317 + echo $this->build_radio_checkbox_field($item, $item_index, $item['field_type']); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1318 + break;
2166 1319
2167 1320 case 'address': // is actually honeypot
2168 1321 // PHPCS - the method build_honeypot_field is safe.
2169 - echo $this->build_honeypot_field( $item, $item_index ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1322 + echo $this->build_honeypot_field($item, $item_index); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2170 1323 break;
2171 1324
2172 1325 case 'recaptcha':
2173 1326 // get widget ID
2174 - echo '<input type="hidden" name="recaptcha"/> <div id="ui-e-recaptcha-'.esc_attr($this->get_ID()).'"></div>';
1327 + echo '<input type="hidden" name="recaptcha"/> <div id="ui-e-recaptcha-' . esc_attr($this->get_ID()) . '"></div>';
2175 1328 break;
2176 1329
2177 1330 case 'recaptcha_v3':
2178 1331 echo '<input type="hidden" name="recaptcha_v3"/>';
@@ -2177,283 +1330,71 @@
2177 1330 case 'recaptcha_v3':
2178 1331 echo '<input type="hidden" name="recaptcha_v3"/>';
2179 1332 break;
2180 1333
2181 - // All other cases are covered by the add_render_atribute()
2182 - default:
2183 - $this->add_render_attribute('input' . $item_index, 'class', 'ui-e-field-textual');
2184 - ?>
2185 - <input size="1" <?php $this->print_render_attribute_string( 'input' . $item_index ); ?>>
2186 - <?php
2187 - break;
1334 + // All other cases are covered by the add_render_atribute()
1335 + default:
1336 + $this->add_render_attribute('input' . $item_index, 'class', 'ui-e-field-textual');
1337 + ?>
1338 + <input size="1" <?php $this->print_render_attribute_string('input' . $item_index); ?>>
1339 + <?php
1340 + break;
2188 1341
2189 - endswitch;
2190 - ?>
2191 - </div>
1342 + endswitch;
1343 + ?>
1344 + </div>
2192 1345
2193 - <?php endforeach; ?>
1346 + <?php endforeach; ?>
2194 1347
2195 - <div <?php $this->print_render_attribute_string( 'submit-group' ); ?>>
2196 - <button type="submit" <?php $this->print_render_attribute_string( 'button' ); ?>>
2197 - <span <?php $this->print_render_attribute_string( 'content-wrapper' ); ?>>
2198 - <?php if ( ! empty( $instance['button_icon'] ) || ! empty( $instance['selected_button_icon'] ) ) : ?>
2199 - <span <?php $this->print_render_attribute_string( 'icon-align' ); ?>>
2200 - <?php Icons_Manager::render_icon( $instance['selected_button_icon'], [ 'aria-hidden' => 'true' ] ); ?>
2201 - <?php if ( empty( $instance['button_text'] ) ) : ?>
2202 - <span class="elementor-screen-only"><?php echo esc_html__( 'Submit', 'uicore-elements' ); ?></span>
2203 - <?php endif; ?>
2204 - </span>
2205 - <?php endif; ?>
2206 - <?php if ( ! empty( $instance['button_text'] ) ) : ?>
2207 - <span class="ui-e-text"><?php $this->print_unescaped_setting( 'button_text' ); ?></span>
2208 - <?php endif; ?>
2209 - </span>
2210 - </button>
2211 - </div>
1348 + <div <?php $this->print_render_attribute_string('submit-group'); ?>>
1349 + <button type="submit" <?php $this->print_render_attribute_string('button'); ?>>
1350 + <span <?php $this->print_render_attribute_string('content-wrapper'); ?>>
1351 + <?php if (! empty($instance['button_icon']) || ! empty($instance['selected_button_icon'])) : ?>
1352 + <span <?php $this->print_render_attribute_string('icon-align'); ?>>
1353 + <?php Icons_Manager::render_icon($instance['selected_button_icon'], ['aria-hidden' => 'true']); ?>
1354 + <?php if (empty($instance['button_text'])) : ?>
1355 + <span class="elementor-screen-only"><?php echo esc_html__('Submit', 'uicore-elements'); ?></span>
1356 + <?php endif; ?>
1357 + </span>
1358 + <?php endif; ?>
1359 + <?php if (! empty($instance['button_text'])) : ?>
1360 + <span class="ui-e-text"><?php $this->print_unescaped_setting('button_text'); ?></span>
1361 + <?php endif; ?>
1362 + </span>
1363 + </button>
1364 + </div>
2212 1365
2213 - </div>
1366 + </div>
2214 1367
2215 1368 <div class="ui-e-message <?php echo $this->is_edit_mode() ? 'elementor-hidden' : ''; ?>">
2216 - <?php if($this->is_edit_mode()) :
1369 + <?php if ($this->is_edit_mode()) :
2217 1370 // Get custom messages if set, else use default
2218 - $messages = Contact_Form_Service::get_default_messages();
2219 - $success = isset($instance['success_message']) ? $instance['success_message'] : $messages['success'];
2220 - $error = isset($instance['error_message']) ? $instance['error_message'] : $messages['error'];
2221 - ?>
2222 - <span class="success"> <?php echo esc_html($success);?> </span> <br>
2223 - <span class="error"> <?php echo esc_html($error);?> </span>
2224 - <?php endif; ?>
1371 + $success = isset($instance['success_message'])
1372 + ? $instance['success_message']
1373 + : $messages['success'];
1374 + $error = isset($instance['error_message'])
1375 + ? $instance['error_message']
1376 + : $messages['error'];
1377 + ?>
1378 + <span class="success"> <?php echo esc_html($success); ?> </span> <br>
1379 + <span class="error"> <?php echo esc_html($error); ?> </span>
1380 + <?php endif; ?>
2225 1381 </div>
2226 - </form>
2227 - <?php
1382 + </form>
1383 + <?php
2228 1384
2229 1385 //add js to footer if recaptcha is enabled
2230 - if($is_recaptcha_required){
1386 + if ($is_recaptcha_required) {
2231 1387 add_action('wp_footer', [$this, 'recaptcha_js'], 999);
2232 1388 }
2233 - }
2234 - protected function content_template() {
2235 - ?>
2236 - <#
2237 - view.addRenderAttribute(
2238 - 'form',
2239 - {
2240 - 'id': settings.form_id,
2241 - 'name': settings.form_name,
2242 - }
2243 - );
2244 - if ( 'no' === settings.form_validation ) {
2245 - view.addRenderAttribute( 'form', 'novalidate' );
2246 - }
2247 - #>
2248 - <form class="ui-e-form" {{{ view.getRenderAttributeString( 'form' ) }}}>
2249 - <div class="ui-e-fields-wrp">
2250 - <#
2251 - for ( var i in settings.form_fields ) {
2252 - var item = settings.form_fields[ i ];
2253 - item.field_type = _.escape( item.field_type );
2254 - item.field_value = _.escape( item.field_value );
2255 1389
2256 - var options = item.field_options ? item.field_options.split( '\n' ) : [],
2257 - itemClasses = _.escape( item.css_classes ),
2258 - labelVisibility = '',
2259 - placeholder = '',
2260 - required = '',
2261 - checked_by_default = '',
2262 - inputField = '',
2263 - multiple = '',
2264 - fieldGroupClasses = 'ui-e-field-group elementor-column ui-e-field-type-' + item.field_type,
2265 - printLabel = settings.show_labels && ! [ 'hidden', 'html', 'recaptcha', 'recaptcha_v3' ].includes( item.field_type );
2266 -
2267 - fieldGroupClasses += ' elementor-col-' + ( ( '' !== item.width ) ? item.width : '100' );
2268 -
2269 - if ( item.width_tablet ) {
2270 - fieldGroupClasses += ' elementor-md-' + item.width_tablet;
2271 - }
2272 -
2273 - if ( item.width_mobile ) {
2274 - fieldGroupClasses += ' elementor-sm-' + item.width_mobile;
2275 - }
2276 -
2277 - if ( item.required ) {
2278 - required = 'required';
2279 - fieldGroupClasses += ' ui-e-field-required';
2280 -
2281 - if ( settings.mark_required ) {
2282 - fieldGroupClasses += ' ui-e-required';
2283 - }
2284 - }
2285 -
2286 - if ( item.placeholder ) {
2287 - placeholder = 'placeholder="' + _.escape( item.placeholder ) + '"';
2288 - }
2289 -
2290 - if ( item.allow_multiple ) {
2291 - multiple = ' multiple';
2292 - fieldGroupClasses += ' ui-e-field-type-' + item.field_type + '-multiple';
2293 - }
2294 -
2295 - switch ( item.field_type ) {
2296 - case 'html':
2297 - inputField = item.field_html;
2298 - break;
2299 -
2300 - case 'textarea':
2301 - inputField = '<textarea class="ui-e-field ui-e-field-textual elementor-size-' + settings.input_size + ' ' + itemClasses + '" name="form_field_' + i + '" id="form_field_' + i + '" rows="' + item.rows + '" ' + required + ' ' + placeholder + '>' + item.field_value + '</textarea>';
2302 - break;
2303 -
2304 - case 'select':
2305 - if ( options ) {
2306 - var size = '';
2307 - if ( item.allow_multiple && item.select_size ) {
2308 - size = ' size="' + item.select_size + '"';
2309 - }
2310 - inputField = '<div class="ui-e-field ui-e-field-select ui-e-field-subgroup' + itemClasses + '">';
2311 - inputField += '<select class="ui-e-field-textual" name="form_field_' + i + '" id="form_field_' + i + '" ' + required + multiple + size + ' >';
2312 - for ( var x in options ) {
2313 - var option_value = options[ x ];
2314 - var option_label = options[ x ];
2315 - var option_id = 'form_field_option' + i + x;
2316 -
2317 - if ( options[ x ].indexOf( '|' ) > -1 ) {
2318 - var label_value = options[ x ].split( '|' );
2319 - option_label = label_value[0];
2320 - option_value = label_value[1];
2321 - }
2322 -
2323 - view.addRenderAttribute( option_id, 'value', option_value );
2324 - if ( item.field_value.split( ',' ) .indexOf( option_value ) ) {
2325 - view.addRenderAttribute( option_id, 'selected', 'selected' );
2326 - }
2327 - inputField += '<option ' + view.getRenderAttributeString( option_id ) + '>' + option_label + '</option>';
2328 - }
2329 - inputField += '</select></div>';
2330 - }
2331 - break;
2332 -
2333 - case 'radio':
2334 - case 'checkbox':
2335 - if ( options ) {
2336 - var multiple = '';
2337 -
2338 - if ( 'checkbox' === item.field_type && options.length > 1 ) {
2339 - multiple = '[]';
2340 - }
2341 -
2342 - inputField = '<div class="ui-e-field-subgroup ' + itemClasses + ' ' + _.escape( item.inline_list ) + '">';
2343 -
2344 - for ( var x in options ) {
2345 - var option_value = options[ x ];
2346 - var option_label = options[ x ];
2347 - var option_id = 'form_field_' + item.field_type + i + x;
2348 - if ( options[x].indexOf( '|' ) > -1 ) {
2349 - var label_value = options[x].split( '|' );
2350 - option_label = label_value[0];
2351 - option_value = label_value[1];
2352 - }
2353 -
2354 - view.addRenderAttribute( option_id, {
2355 - value: option_value,
2356 - type: item.field_type,
2357 - id: 'form_field_' + i + '-' + x,
2358 - name: 'form_field_' + i + multiple
2359 - } );
2360 -
2361 - if ( option_value === item.field_value ) {
2362 - view.addRenderAttribute( option_id, 'checked', 'checked' );
2363 - }
2364 -
2365 - inputField += '<span class="ui-e-field-option"><input ' + view.getRenderAttributeString( option_id ) + ' ' + required + '> ';
2366 - inputField += '<label for="form_field_' + i + '-' + x + '">' + option_label + '</label></span>';
2367 -
2368 - }
2369 -
2370 - inputField += '</div>';
2371 - }
2372 - break;
2373 -
2374 - case 'acceptance' :
2375 - var checked = '';
2376 - if(item.checked_by_default == 'yes') {
2377 - checked = ' checked';
2378 - }
2379 - inputField += '<div class="ui-e-field-subgroup">';
2380 - inputField += '<input type="checkbox" class="ui-e-field ui-e-acceptance-field" name="form_field_' + i + '" id="form_field_' + i + '" ' + required + checked + '>';
2381 - inputField += '<label for="form_field_' + i + '">' + item.acceptance_text + '</label>';
2382 - inputField += '</div>';
2383 - break;
2384 -
2385 - case 'recaptcha' :
2386 - case 'recaptcha_v3' :
2387 - inputField = '<input type="hidden" name="recaptcha"/> <div id="ui-e-recaptcha"></div>';
2388 - break;
2389 -
2390 - default:
2391 - itemClasses = 'ui-e-field-textual ' + itemClasses;
2392 - inputField = '<input size="1" type="' + item.field_type + '" value="' + item.field_value + '" class="ui-e-field elementor-size-' + settings.input_size + ' ' + itemClasses + '" name="form_field_' + i + '" id="form_field_' + i + '" ' + required + ' ' + placeholder + ' >';
2393 - break;
2394 - }
2395 -
2396 - if ( inputField ) {
2397 - #>
2398 - <div class="{{ fieldGroupClasses }}">
2399 -
2400 - <# if ( printLabel && item.field_label ) { #>
2401 - <label class="ui-e-field-label" for="form_field_{{ i }}" {{{ labelVisibility }}}>{{{ item.field_label }}}</label>
2402 - <# } #>
2403 -
2404 - {{{ inputField }}}
2405 - </div>
2406 - <#
2407 - }
2408 - }
2409 -
2410 -
2411 - var buttonClasses = 'ui-e-field-group elementor-column ui-e-field-type-submit e-form__buttons';
2412 -
2413 - buttonClasses += ' elementor-col-' + ( ( '' !== settings.button_width ) ? settings.button_width : '100' );
2414 -
2415 - if ( settings.button_width_tablet ) {
2416 - buttonClasses += ' elementor-md-' + settings.button_width_tablet;
2417 - }
2418 -
2419 - if ( settings.button_width_mobile ) {
2420 - buttonClasses += ' elementor-sm-' + settings.button_width_mobile;
2421 - }
2422 -
2423 - var iconHTML = elementor.helpers.renderIcon( view, settings.selected_button_icon, { 'aria-hidden': true }, 'i' , 'object' )
2424 - #>
2425 -
2426 - <div class="{{ buttonClasses }}">
2427 - <button id="{{ settings.button_css_id }}" type="submit" class="elementor-button elementor-animation-{{ settings.button_hover_animation }}">
2428 - <span>
2429 - <# if ( settings.button_icon || settings.selected_button_icon ) { #>
2430 - <span class="ui-e-icon ui-e-align-{{ settings.button_icon_align }}">
2431 - <# if ( iconHTML && iconHTML.rendered && ( ! settings.button_icon ) ) { #>
2432 - {{{ iconHTML.value }}}
2433 - <# } else { #>
2434 - <i class="{{ settings.button_icon }}" aria-hidden="true"></i>
2435 - <# } #>
2436 - <span class="elementor-screen-only"><?php echo esc_html__( 'Submit', 'uicore-elements' ); ?></span>
2437 - </span>
2438 - <# } #>
2439 -
2440 - <# if ( settings.button_text ) { #>
2441 - <span class="ui-e-text">{{{ settings.button_text }}}</span>
2442 - <# } #>
2443 - </span>
2444 - </button>
2445 - </div>
2446 - </div>
2447 - <div class="ui-e-message elementor-hidden">
2448 - <#
2449 - const success = settings.success_message;
2450 - const error = settings.error_message;
2451 - #>
2452 - <span class="success">{{{ success }}}</span> <br>
2453 - <span class="error">{{{ error }}}</span>
2454 - </div>
2455 - </form>
2456 - <?php
2457 - }
1390 + // Add frontend validation messages to js var
1391 + ?>
1392 + <script>
1393 + window.ui_e_form_validation_messages = <?php echo json_encode([
1394 + 'required_fields' => esc_html($front_msg_required),
1395 + ]); ?>;
1396 + </script>
1397 +<?php
1398 + }
2458 1399 }
2459 -\Elementor\Plugin::instance()->widgets_manager->register(new ContactForm());
1400 +\Elementor\Plugin::instance()->widgets_manager->register(new ContactForm());