PluginProbe
UiCore Elements – Free widgets and templates for Elementor / 1.0.5
UiCore Elements – Free widgets and templates for Elementor v1.0.5
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.5, at includes/widgets/contact-form.php

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