PluginProbe
UiCore Elements – Free widgets and templates for Elementor / 1.0.14
UiCore Elements – Free widgets and templates for Elementor v1.0.14
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 1.2.4 All 41 releases
uicore-elements / includes / widgets / contact-form.php

contact-form.php in UiCore Elements – Free widgets and templates for Elementor 1.0.14, at includes/widgets/contact-form.php

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