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

1,624 lines 59.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace UiCoreElements;
4
5 use UiCoreElements\Helper;
6 use UiCoreElements\Utils\Contact_Form_Service;
7 use UiCoreElements\Utils\Form_Component;
8 use UiCoreElements\Utils\Newsletter_Services;
9
10 use Elementor\Controls_Manager;
11 use Elementor\Icons_Manager;
12 use Elementor\Utils;
13 use Elementor\Repeater;
14 use Elementor\Group_Control_Typography;
15 use Elementor\Group_Control_Border;
16 use Elementor\Core\Kits\Documents\Tabs\Global_Colors;
17 use Elementor\Core\Kits\Documents\Tabs\Global_Typography;
18
19
20 defined('ABSPATH') || exit();
21
22 /**
23 * Contact Form
24 *
25 * @author Lucas Marini Falbo <lucas@uicore.co>
26 * @since 1.0.5
27 */
28
29 class ContactForm extends UiCoreWidget
30 {
31
32 use Form_Component;
33
34 public function get_name()
35 {
36 return 'uicore-contact-form';
37 }
38
39 public function get_title()
40 {
41 return __('Contact Form', 'uicore-elements');
42 }
43
44 public function get_icon()
45 {
46 return 'eicon-form-horizontal ui-e-widget';
47 }
48 public function get_categories()
49 {
50 return ['uicore'];
51 }
52 public function get_keywords()
53 {
54 return ['form', 'forms', 'contact', 'mail', 'send', 'field', 'button', 'recaptcha',];
55 }
56 public function get_styles()
57 {
58 return ['contact-form'];
59 }
60 public function get_scripts()
61 {
62 return [
63 'contact-form',
64 'recaptcha' => [
65 'custom_condition' => $this->check_recaptcha_version('v2')
66 ],
67 'recaptcha-v3' => [
68 'custom_condition' => $this->check_recaptcha_version('v3')
69 ],
70 'repeater-custom-key' => [
71 'custom_condition' => $this->is_edit_mode()
72 ]
73 ];
74 }
75 public function has_widget_inner_wrapper(): bool
76 {
77 // TODO: remove after Optmized Markup experiment is merged to the core
78 return ! \Elementor\Plugin::$instance->experiments->is_feature_active('e_optimized_markup');;
79 }
80 function check_recaptcha_version($version)
81 {
82
83 if ($this->is_edit_mode()) {
84 return true;
85 }
86 $settings = $this->get_settings_for_display();
87 foreach ($settings['form_fields'] as $field) {
88 $version_to_check = $version === 'v2' ? 'recaptcha' : 'recaptcha_v3';
89 if ($field['field_type'] === $version_to_check) {
90 return true;
91 }
92 }
93 return false;
94 }
95
96 // Helper Functions
97 function get_field_types()
98 {
99 return [
100 'text' => esc_html__('Text', 'uicore-elements'),
101 'email' => esc_html__('Email', 'uicore-elements'),
102 'textarea' => esc_html__('Textarea', 'uicore-elements'),
103 'url' => esc_html__('URL', 'uicore-elements'),
104 'tel' => esc_html__('Tel', 'uicore-elements'),
105 'radio' => esc_html__('Radio', 'uicore-elements'),
106 'select' => esc_html__('Select', 'uicore-elements'),
107 'checkbox' => esc_html__('Checkbox', 'uicore-elements'),
108 'acceptance' => esc_html__('Acceptance', 'uicore-elements'),
109 'number' => esc_html__('Number', 'uicore-elements'),
110 'date' => esc_html__('Date', 'uicore-elements'),
111 'time' => esc_html__('Time', 'uicore-elements'),
112 'file' => esc_html__('File Upload', 'uicore-elements'),
113 'password' => esc_html__('Password', 'uicore-elements'),
114 'address' => esc_html__('Honeypot', 'uicore-elements'),
115 'recaptcha' => esc_html__('reCAPTCHA', 'uicore-elements'),
116 'recaptcha_v3' => esc_html__('reCAPTCHA V3', 'uicore-elements'),
117 'html' => esc_html__('HTML', 'uicore-elements'),
118 'hidden' => esc_html__('Hidden', 'uicore-elements'),
119 ];
120 }
121
122 function get_attribute_name($item)
123 {
124 return "form_fields[{$item['custom_id']}]";
125 }
126 function get_attribute_id($item)
127 {
128 return 'form-field-' . $item['custom_id'];
129 }
130 function add_required_attribute($element, $js_verication = false)
131 {
132
133 // Used for elements (eg: checkbox) that aren't natively supported by the browsers validations
134 if ($js_verication) {
135 $this->add_render_attribute($element, 'data-ui-e-required', 'true');
136 return;
137 }
138
139 // Default method
140 $this->add_render_attribute($element, 'required', 'required');
141 $this->add_render_attribute($element, 'aria-required', 'true');
142 }
143
144 // Field Render Functions
145 function build_honeypot_field($item, $item_index)
146 {
147 $this->add_render_attribute('honeypot' . $item_index, [
148 'class' => [
149 'ui-e-field',
150 'ui-e-h-p',
151 esc_attr($item['css_classes']),
152 ],
153 'name' => 'ui-e-h-p',
154 'id' => 'ui-e-h-p',
155 'autocomplete' => 'off',
156 ]);
157
158 if ($item['placeholder']) {
159 $this->add_render_attribute('honeypot' . $item_index, 'placeholder', $item['placeholder']);
160 }
161
162 if ($item['required']) {
163 $this->add_required_attribute('honeypot' . $item_index);
164 }
165
166 $value = empty($item['field_value']) ? '' : $item['field_value'];
167
168 return '<input ' . $this->get_render_attribute_string('honeypot' . $item_index) . ' tabindex="-1">' . $value . '</input>';
169 }
170 function build_textarea_field($item, $item_index)
171 {
172 $this->add_render_attribute('textarea' . $item_index, [
173 'class' => [
174 'ui-e-field',
175 esc_attr($item['css_classes']),
176 ],
177 'name' => $this->get_attribute_name($item),
178 'id' => $this->get_attribute_id($item),
179 'rows' => $item['rows'],
180 ]);
181
182 if ($item['placeholder']) {
183 $this->add_render_attribute('textarea' . $item_index, 'placeholder', $item['placeholder']);
184 }
185
186 if ($item['required']) {
187 $this->add_required_attribute('textarea' . $item_index);
188 }
189
190 $value = empty($item['field_value']) ? '' : $item['field_value'];
191
192 return '<textarea ' . $this->get_render_attribute_string('textarea' . $item_index) . '>' . $value . '</textarea>';
193 }
194 function build_select_field($item, $i)
195 {
196 $this->add_render_attribute(
197 [
198 'select-wrapper' . $i => [
199 'class' => [
200 'ui-e-field',
201 'ui-e-field-select',
202 'ui-e-field-subgroup',
203 esc_attr($item['css_classes']),
204 ],
205 ],
206 'select' . $i => [
207 'name' => $this->get_attribute_name($item) . (! empty($item['allow_multiple']) ? '[]' : ''),
208 'id' => $this->get_attribute_id($item),
209 'class' => [
210 'ui-e-field-textual',
211 ],
212 ],
213 ]
214 );
215
216 if ($item['required']) {
217 $this->add_required_attribute('select' . $i);
218 }
219
220 if ($item['allow_multiple']) {
221 $this->add_render_attribute('select' . $i, 'multiple');
222 if (! empty($item['select_size'])) {
223 $this->add_render_attribute('select' . $i, 'size', $item['select_size']);
224 }
225 }
226
227 $options = preg_split("/\\r\\n|\\r|\\n/", $item['field_options']);
228
229 if (! $options) {
230 return '';
231 }
232
233 ob_start();
234 ?>
235 <div <?php $this->print_render_attribute_string('select-wrapper' . $i); ?>>
236 <select <?php $this->print_render_attribute_string('select' . $i); ?>>
237 <?php
238 foreach ($options as $key => $option) {
239 $option_id = $item['custom_id'] . $key;
240 $option_value = esc_attr($option);
241 $option_label = esc_html($option);
242
243 if (false !== strpos($option, '|')) {
244 list($label, $value) = explode('|', $option);
245 $option_value = esc_attr($value);
246 $option_label = esc_html($label);
247 }
248
249 $this->add_render_attribute($option_id, 'value', $option_value);
250
251 // Support multiple selected values
252 if (! empty($item['field_value']) && in_array($option_value, explode(',', $item['field_value']))) {
253 $this->add_render_attribute($option_id, 'selected', 'selected');
254 } ?>
255 <option <?php $this->print_render_attribute_string($option_id); ?>><?php
256 // PHPCS - $option_label is already escaped
257 echo $option_label; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
258 ?></option>
259 <?php } ?>
260 </select>
261 </div>
262 <?php
263
264 $select = ob_get_clean();
265 return $select;
266 }
267 function build_radio_checkbox_field($item, $item_index, $type)
268 {
269 $options = preg_split("/\\r\\n|\\r|\\n/", $item['field_options']);
270 $html = '';
271 if ($options) {
272 $html .= '<div class="ui-e-field-subgroup ' . esc_attr($item['css_classes']) . ' ' . $item['inline_list'] . '">';
273 foreach ($options as $key => $option) {
274 $element_id = $item['custom_id'] . $key;
275 $html_id = $this->get_attribute_id($item) . '-' . $key;
276 $option_label = $option;
277 $option_value = $option;
278 if (false !== strpos($option, '|')) {
279 list($option_label, $option_value) = explode('|', $option);
280 }
281
282 $this->add_render_attribute(
283 $element_id,
284 [
285 'type' => $type,
286 'value' => $option_value,
287 'id' => $html_id,
288 'name' => $this->get_attribute_name($item) . (('checkbox' === $type && count($options) > 1) ? '[]' : ''),
289 ]
290 );
291
292 if ($item['required']) {
293 $this->add_required_attribute($element_id, true);
294 }
295
296 if (! empty($item['field_value']) && $option_value === $item['field_value']) {
297 $this->add_render_attribute($element_id, 'checked', 'checked');
298 }
299
300 if ($item['required'] && 'radio' === $type) {
301 $this->add_required_attribute($element_id);
302 }
303
304 $html .= '<span class="ui-e-field-option"><input ' . $this->get_render_attribute_string($element_id) . '> <label for="' . $html_id . '">' . $option_label . '</label></span>';
305 }
306 $html .= '</div>';
307 }
308
309 return $html;
310 }
311 function build_acceptance_field($item, $item_index)
312 {
313 $text = '';
314 $this->add_render_attribute('input' . $item_index, 'class', 'ui-e-acceptance-field');
315 $this->add_render_attribute('input' . $item_index, 'type', 'checkbox', true);
316
317 if (! empty($item['acceptance_text'])) {
318 $text = '<label for="' . $this->get_attribute_id($item) . '">' . $item['acceptance_text'] . '</label>';
319 }
320
321 if (! empty($item['checked_by_default'])) {
322 $this->add_render_attribute('input' . $item_index, 'checked', 'checked');
323 }
324
325 ?>
326 <div class="ui-e-field-subgroup <?php echo esc_attr($item['css_classes']); ?>">
327 <input <?php $this->print_render_attribute_string('input' . $item_index); ?>>
328 <?php // PHPCS - the variables $text is safe.
329 echo $text; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
330 ?>
331 </div>
332 <?php
333 }
334 function form_fields_render_attributes($i, $instance, $item)
335 {
336 $this->add_render_attribute(
337 [
338 'field-group' . $i => [
339 'class' => [
340 'ui-e-field-type-' . $item['field_type'],
341 'ui-e-field-group',
342 'elementor-column',
343 'ui-e-field-group-' . $item['custom_id'],
344 ],
345 ],
346 'input' . $i => [
347 'type' => $item['field_type'],
348 'name' => $this->get_attribute_name($item),
349 'id' => $this->get_attribute_id($item),
350 'class' => [
351 'ui-e-field',
352 empty($item['css_classes']) ? '' : esc_attr($item['css_classes']),
353 ],
354 ],
355 'label' . $i => [
356 'for' => $this->get_attribute_id($item),
357 'class' => 'ui-e-label',
358 ],
359 ]
360 );
361
362 if (empty($item['width'])) {
363 $item['width'] = '100';
364 }
365
366 $this->add_render_attribute('field-group' . $i, 'class', 'elementor-col-' . $item['width']);
367
368 if (! empty($item['width_tablet'])) {
369 $this->add_render_attribute('field-group' . $i, 'class', 'elementor-md-' . $item['width_tablet']);
370 }
371
372 if ($item['allow_multiple']) {
373 $this->add_render_attribute('field-group' . $i, 'class', 'ui-e-field-type-' . $item['field_type'] . '-multiple');
374 }
375
376 if (! empty($item['width_mobile'])) {
377 $this->add_render_attribute('field-group' . $i, 'class', 'elementor-sm-' . $item['width_mobile']);
378 }
379
380 // Allow zero as placeholder.
381 if (! Utils::is_empty($item['placeholder'])) {
382 $this->add_render_attribute('input' . $i, 'placeholder', $item['placeholder']);
383 }
384
385 if (! empty($item['field_value'])) {
386 $this->add_render_attribute('input' . $i, 'value', $item['field_value']);
387 }
388
389 if (! $instance['show_labels']) {
390 $this->add_render_attribute('label' . $i, 'class', 'elementor-screen-only');
391 }
392
393 if (! empty($item['required'])) {
394 $class = '';
395 if (! empty($instance['mark_required'])) {
396 $class .= ' ui-e-required';
397 }
398 $this->add_render_attribute('field-group' . $i, 'class', $class);
399 $this->add_required_attribute('input' . $i);
400 }
401 }
402
403 protected function register_controls()
404 {
405
406 // Content Controls
407 // Repeater Controls used by `form_fields` control
408 $repeater = new Repeater();
409 $repeater->start_controls_tabs('form_fields_tabs');
410
411 $repeater->start_controls_tab(
412 'form_fields_content_tab',
413 [
414 'label' => esc_html__('Content', 'uicore-elements'),
415 ]
416 );
417
418 $repeater->add_control(
419 'field_type',
420 [
421 'label' => esc_html__('Type', 'uicore-elements'),
422 'type' => Controls_Manager::SELECT,
423 'options' => $this->get_field_types(),
424 'default' => 'text',
425 ]
426 );
427 $repeater->add_control(
428 'field_label',
429 [
430 'label' => esc_html__('Label', 'uicore-elements'),
431 'type' => Controls_Manager::TEXT,
432 'default' => '',
433 'dynamic' => [
434 'active' => true,
435 ],
436 ]
437 );
438 $repeater->add_control(
439 'placeholder',
440 [
441 'label' => esc_html__('Placeholder', 'uicore-elements'),
442 'type' => Controls_Manager::TEXT,
443 'default' => '',
444 'conditions' => [
445 'terms' => [
446 [
447 'name' => 'field_type',
448 'operator' => 'in',
449 'value' => [
450 'tel',
451 'text',
452 'email',
453 'textarea',
454 'number',
455 'url',
456 'password',
457 ],
458 ],
459 ],
460 ],
461 'dynamic' => [
462 'active' => true,
463 ],
464 ]
465 );
466 $repeater->add_control(
467 'required',
468 [
469 'label' => esc_html__('Required', 'uicore-elements'),
470 'type' => Controls_Manager::SWITCHER,
471 'return_value' => 'true',
472 'default' => '',
473 'conditions' => [
474 'terms' => [
475 [
476 'name' => 'field_type',
477 'operator' => '!in',
478 'value' => [
479 'recaptcha',
480 'recaptcha_v3',
481 'hidden',
482 'html',
483 ],
484 ],
485 ],
486 ],
487 ]
488 );
489 $repeater->add_control(
490 'field_options',
491 [
492 'label' => esc_html__('Options', 'uicore-elements'),
493 'type' => Controls_Manager::TEXTAREA,
494 'default' => '',
495 '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'),
496 'conditions' => [
497 'terms' => [
498 [
499 'name' => 'field_type',
500 'operator' => 'in',
501 'value' => [
502 'select',
503 'checkbox',
504 'radio',
505 ],
506 ],
507 ],
508 ],
509 ]
510 );
511 $repeater->add_control(
512 'allow_multiple',
513 [
514 'label' => esc_html__('Multiple Selection', 'uicore-elements'),
515 'type' => Controls_Manager::SWITCHER,
516 'return_value' => 'true',
517 'conditions' => [
518 'terms' => [
519 [
520 'name' => 'field_type',
521 'value' => 'select',
522 ],
523 ],
524 ],
525 ]
526 );
527 $repeater->add_control(
528 'select_size',
529 [
530 'label' => esc_html__('Rows', 'uicore-elements'),
531 'type' => Controls_Manager::NUMBER,
532 'min' => 2,
533 'step' => 1,
534 'conditions' => [
535 'terms' => [
536 [
537 'name' => 'field_type',
538 'value' => 'select',
539 ],
540 [
541 'name' => 'allow_multiple',
542 'value' => 'true',
543 ],
544 ],
545 ],
546 ]
547 );
548 $repeater->add_control(
549 'inline_list',
550 [
551 'label' => esc_html__('Inline List', 'uicore-elements'),
552 'type' => Controls_Manager::SWITCHER,
553 'return_value' => 'ui-e-subgroup-inline',
554 'default' => '',
555 'conditions' => [
556 'terms' => [
557 [
558 'name' => 'field_type',
559 'operator' => 'in',
560 'value' => [
561 'checkbox',
562 'radio',
563 ],
564 ],
565 ],
566 ],
567 ]
568 );
569 $repeater->add_control(
570 'field_html',
571 [
572 'label' => esc_html__('HTML', 'uicore-elements'),
573 'type' => Controls_Manager::TEXTAREA,
574 'dynamic' => [
575 'active' => true,
576 ],
577 'conditions' => [
578 'terms' => [
579 [
580 'name' => 'field_type',
581 'value' => 'html',
582 ],
583 ],
584 ],
585 ]
586 );
587 $repeater->add_control(
588 'acceptance_text',
589 [
590 'label' => esc_html__('Acceptance Text', 'uicore-elements'),
591 'type' => Controls_Manager::TEXTAREA,
592 'condition' => [
593 'field_type' => 'acceptance',
594 ],
595 ],
596 );
597 $repeater->add_control(
598 'checked_by_default',
599 [
600 'label' => esc_html__('Checked by Default', 'uicore-elements'),
601 'type' => Controls_Manager::SWITCHER,
602 'condition' => [
603 'field_type' => 'acceptance',
604 ],
605 ],
606 );
607 $repeater->add_responsive_control(
608 'width',
609 [
610 'label' => esc_html__('Column Width', 'uicore-elements'),
611 'type' => Controls_Manager::SELECT,
612 'options' => [
613 '' => esc_html__('Default', 'uicore-elements'),
614 '100' => '100%',
615 '80' => '80%',
616 '75' => '75%',
617 '70' => '70%',
618 '66' => '66%',
619 '60' => '60%',
620 '50' => '50%',
621 '40' => '40%',
622 '33' => '33%',
623 '30' => '30%',
624 '25' => '25%',
625 '20' => '20%',
626 ],
627 'default' => '100',
628 'conditions' => [
629 'terms' => [
630 [
631 'name' => 'field_type',
632 'operator' => '!in',
633 'value' => [
634 'hidden',
635 'recaptcha',
636 'recaptcha_v3'
637 ],
638 ],
639 ],
640 ],
641 ]
642 );
643 $repeater->add_control(
644 'rows',
645 [
646 'label' => esc_html__('Rows', 'uicore-elements'),
647 'type' => Controls_Manager::NUMBER,
648 'default' => 4,
649 'conditions' => [
650 'terms' => [
651 [
652 'name' => 'field_type',
653 'value' => 'textarea',
654 ],
655 ],
656 ],
657 ]
658 );
659 $repeater->add_control(
660 'recaptcha_hide',
661 [
662 'label' => esc_html__('Badge', 'uicore-elements'),
663 'type' => Controls_Manager::SELECT,
664 'default' => 'hidden',
665 'options' => [
666 'hidden' => esc_html__('Hidden', 'uicore-elements'),
667 'visible' => esc_html__('Visible', 'uicore-elements')
668 ],
669 'condition' => [
670 'field_type' => 'recaptcha_v3',
671 ],
672 'selectors' => [
673 '.grecaptcha-badge' => 'visibility: {{VALUE}};',
674 ],
675 ]
676 );
677 $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
678 $repeater->add_control(
679 'recaptcha_warning',
680 [
681 'type' => Controls_Manager::ALERT,
682 'alert_type' => 'warning',
683 'dismissible' => false,
684 'heading' => esc_html__("You haven't set your reCAPTCHA API keys yet.", 'uicore-elements'),
685 'content' => Helper::get_admin_settings_url(esc_html__("Click here to configure your API keys.", 'uicore-elements')),
686 'condition' => [
687 'field_type' => $recaptcha_keys ? ['recaptcha', 'recaptcha_v3'] : [],
688 ]
689 ]
690 );
691
692 $repeater->end_controls_tab();
693
694 $repeater->start_controls_tab(
695 'form_fields_advanced_tab',
696 [
697 'label' => esc_html__('Advanced', 'uicore-elements'),
698 'condition' => [
699 'field_type!' => ['html', 'address'],
700 ],
701 ]
702 );
703
704 $repeater->add_control(
705 'field_value',
706 [
707 'label' => esc_html__('Default Value', 'uicore-elements'),
708 'type' => Controls_Manager::TEXT,
709 'default' => '',
710 'dynamic' => [
711 'active' => true,
712 ],
713 'ai' => [
714 'active' => false,
715 ],
716 'conditions' => [
717 'terms' => [
718 [
719 'name' => 'field_type',
720 'operator' => 'in',
721 'value' => [
722 'text',
723 'email',
724 'textarea',
725 'url',
726 'tel',
727 'radio',
728 'select',
729 'number',
730 'date',
731 'time',
732 'hidden',
733 ],
734 ],
735 ],
736 ],
737 ]
738 );
739 $repeater->add_control(
740 'custom_id',
741 [
742 'label' => esc_html__('ID', 'uicore-elements'),
743 'type' => Controls_Manager::TEXT,
744 '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'),
745 'render_type' => 'none',
746 'required' => true,
747 'dynamic' => [
748 'active' => true,
749 ],
750 'ai' => [
751 'active' => false,
752 ],
753 ]
754 );
755 $repeater->add_control(
756 'css_classes',
757 [
758 'label' => esc_html__('Custom Class', 'uicore-elements'),
759 'type' => Controls_Manager::TEXT,
760 'default' => '',
761 'ai' => [
762 'active' => false,
763 ],
764 'placeholder' => esc_html__('e.g: my-class', 'uicore-elements'),
765 ]
766 );
767 $shortcode_template = '{{ view.container.settings.get( \'custom_id\' ) }}';
768 $repeater->add_control(
769 'shortcode',
770 [
771 'label' => esc_html__('Shortcode', 'uicore-elements'),
772 'type' => Controls_Manager::RAW_HTML,
773 'classes' => 'forms-field-shortcode',
774 'raw' => '<input class="elementor-form-field-shortcode" value=\'[field id="' . $shortcode_template . '"]\' readonly />',
775 'label_block' => false,
776 ]
777 );
778
779 $repeater->end_controls_tab();
780
781 $repeater->end_controls_tabs();
782
783 $this->start_controls_section(
784 'section_form_fields',
785 [
786 'label' => esc_html__('Form Fields', 'uicore-elements'),
787 ]
788 );
789
790
791 $this->add_control(
792 'form_name',
793 [
794 'label' => esc_html__('Form Name', 'uicore-elements'),
795 'type' => Controls_Manager::TEXT,
796 'default' => esc_html__('New Form', 'uicore-elements'),
797 'placeholder' => esc_html__('Form Name', 'uicore-elements'),
798 ]
799 );
800 $this->add_control(
801 'form_fields',
802 [
803 'type' => Controls_Manager::REPEATER,
804 'fields' => $repeater->get_controls(),
805 'default' => [
806 [
807 'custom_id' => 'name',
808 'field_type' => 'text',
809 'field_label' => esc_html__('Name', 'uicore-elements'),
810 'placeholder' => esc_html__('Name', 'uicore-elements'),
811 'width' => '100',
812 'dynamic' => [
813 'active' => true,
814 ],
815 ],
816 [
817 'custom_id' => 'email',
818 'field_type' => 'email',
819 'required' => 'true',
820 'field_label' => esc_html__('Email', 'uicore-elements'),
821 'placeholder' => esc_html__('Email', 'uicore-elements'),
822 'width' => '100',
823 ],
824 [
825 'custom_id' => 'address',
826 'field_type' => 'address',
827 'field_label' => esc_html__('address (honeypot)', 'uicore-elements'),
828 'placeholder' => esc_html__('address', 'uicore-elements'),
829 'width' => '100',
830 ],
831 [
832 'custom_id' => 'message',
833 'field_type' => 'textarea',
834 'field_label' => esc_html__('Message', 'uicore-elements'),
835 'placeholder' => esc_html__('Message', 'uicore-elements'),
836 'width' => '100',
837 ],
838 ],
839 'title_field' => '{{{ field_label }}}',
840 ]
841 );
842 $this->add_control(
843 'show_labels',
844 [
845 'label' => esc_html__('Label', 'uicore-elements'),
846 'type' => Controls_Manager::SWITCHER,
847 'label_on' => esc_html__('Show', 'uicore-elements'),
848 'label_off' => esc_html__('Hide', 'uicore-elements'),
849 'return_value' => 'true',
850 'default' => 'true',
851 'separator' => 'before',
852 ]
853 );
854 $this->add_control(
855 'mark_required',
856 [
857 'label' => esc_html__('Required Mark', 'uicore-elements'),
858 'type' => Controls_Manager::SWITCHER,
859 'label_on' => esc_html__('Show', 'uicore-elements'),
860 'label_off' => esc_html__('Hide', 'uicore-elements'),
861 'default' => '',
862 'render_type' => 'template',
863 'condition' => [
864 'show_labels!' => '',
865 ],
866 ]
867 );
868
869 $this->end_controls_section();
870
871 $this->start_controls_section(
872 'section_buttons',
873 [
874 'label' => esc_html__('Button', 'uicore-elements'),
875 ]
876 );
877
878 $this->add_responsive_control(
879 'button_width',
880 [
881 'label' => esc_html__('Column Width', 'uicore-elements'),
882 'type' => Controls_Manager::SELECT,
883 'options' => [
884 '' => esc_html__('Default', 'uicore-elements'),
885 '100' => '100%',
886 '80' => '80%',
887 '75' => '75%',
888 '70' => '70%',
889 '66' => '66%',
890 '60' => '60%',
891 '50' => '50%',
892 '40' => '40%',
893 '33' => '33%',
894 '30' => '30%',
895 '25' => '25%',
896 '20' => '20%',
897 ],
898 'default' => '100',
899 ]
900 );
901 $this->add_responsive_control(
902 'button_align',
903 [
904 'label' => esc_html__('Alignment', 'uicore-elements'),
905 'type' => Controls_Manager::CHOOSE,
906 'options' => [
907 'left' => [
908 'title' => esc_html__('Left', 'uicore-elements'),
909 'icon' => 'eicon-text-align-left',
910 ],
911 'center' => [
912 'title' => esc_html__('Center', 'uicore-elements'),
913 'icon' => 'eicon-text-align-center',
914 ],
915 'right' => [
916 'title' => esc_html__('Right', 'uicore-elements'),
917 'icon' => 'eicon-text-align-right',
918 ],
919 'stretch' => [
920 'title' => esc_html__('Justified', 'uicore-elements'),
921 'icon' => 'eicon-text-align-justify',
922 ],
923 ],
924 'default' => 'stretch',
925 'prefix_class' => 'ui-e-submit-align-%s-',
926 ]
927 );
928 $this->add_control(
929 'button_text',
930 [
931 'label' => esc_html__('Submit', 'uicore-elements'),
932 'type' => Controls_Manager::TEXT,
933 'default' => esc_html__('Send', 'uicore-elements'),
934 'placeholder' => esc_html__('Send', 'uicore-elements'),
935 'dynamic' => [
936 'active' => true,
937 ],
938 'ai' => [
939 'active' => false,
940 ],
941 ]
942 );
943 $this->add_control(
944 'selected_button_icon',
945 [
946 'label' => esc_html__('Icon', 'uicore-elements'),
947 'type' => Controls_Manager::ICONS,
948 'skin' => 'inline',
949 'label_block' => false,
950 ]
951 );
952 $this->add_control(
953 'button_icon_align',
954 [
955 'label' => esc_html__('Icon Position', 'uicore-elements'),
956 'type' => Controls_Manager::SELECT,
957 'default' => 'left',
958 'options' => [
959 'left' => esc_html__('Before', 'uicore-elements'),
960 'right' => esc_html__('After', 'uicore-elements'),
961 ],
962 'condition' => [
963 'selected_button_icon[value]!' => '',
964 ],
965 ]
966 );
967 $this->add_control(
968 'button_icon_indent',
969 [
970 'label' => esc_html__('Icon Spacing', 'uicore-elements'),
971 'type' => Controls_Manager::SLIDER,
972 'size_units' => ['px', 'em', 'rem', 'custom'],
973 'range' => [
974 'px' => [
975 'max' => 100,
976 ],
977 'em' => [
978 'max' => 10,
979 ],
980 'rem' => [
981 'max' => 10,
982 ],
983 ],
984 'condition' => [
985 'selected_button_icon[value]!' => '',
986 ],
987 'selectors' => [
988 '{{WRAPPER}} .elementor-button .ui-e-align-right' => 'margin-left: {{SIZE}}{{UNIT}};',
989 '{{WRAPPER}} .elementor-button .ui-e-align-left' => 'margin-right: {{SIZE}}{{UNIT}};',
990 ],
991 ]
992 );
993 $this->add_control(
994 'button_css_id',
995 [
996 'label' => esc_html__('Button ID', 'uicore-elements'),
997 'type' => Controls_Manager::TEXT,
998 'default' => '',
999 'ai' => [
1000 'active' => false,
1001 ],
1002 'title' => esc_html__('Add your custom id WITHOUT the Pound key. e.g: my-id', 'uicore-elements'),
1003 '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'),
1004 'separator' => 'before',
1005 'dynamic' => [
1006 'active' => true,
1007 ],
1008 ]
1009 );
1010
1011
1012 $this->end_controls_section();
1013
1014 $this->TRAIT_register_submit_actions_controls(Contact_Form_Service::get_form_submit_options());
1015
1016 // Submit sections
1017 $this->start_controls_section(
1018 'section_email',
1019 [
1020 'label' => esc_html__('Email', 'uicore-elements'),
1021 'condition' => [
1022 'submit_actions' => 'email',
1023 ],
1024 ]
1025 );
1026
1027 $this->TRAIT_register_submit_email_controls($this);
1028
1029 $this->end_controls_section();
1030
1031 $this->start_controls_section(
1032 'section_email_2',
1033 [
1034 'label' => esc_html__('Email 2', 'uicore-elements'),
1035 'condition' => [
1036 'submit_actions' => 'email_2',
1037 ],
1038 ]
1039 );
1040
1041 $this->TRAIT_register_submit_email_controls($this, '_2');
1042
1043 $this->end_controls_section();
1044
1045 $this->TRAIT_register_submit_redirect_controls();
1046 $this->TRAIT_register_submit_popup_controls($this);
1047 $this->TRAIT_register_submit_webhook_controls();
1048 $this->TRAIT_register_submit_newsletter_services_controls(Newsletter_Services::get_services_list('keys'), true);
1049 $default_messages = Contact_Form_Service::get_default_messages();
1050 $this->TRAIT_register_additional_controls($default_messages);
1051
1052 $this->TRAIT_register_all_form_style_controls();
1053
1054 // Custom Fields additional Controls injection
1055 $this->start_injection([
1056 'of' => 'redirect_message',
1057 'at' => 'before',
1058 ]);
1059 $this->add_control(
1060 'required_fields_message',
1061 [
1062 'label' => esc_html__('Required Fields', 'uicore-elements'),
1063 'type' => Controls_Manager::TEXT,
1064 'default' => $default_messages['required'],
1065 'placeholder' => $default_messages['required'],
1066 'label_block' => true,
1067 'conditions' => [
1068 'terms' => [
1069 [
1070 'name' => 'custom_messages',
1071 'operator' => '!=',
1072 'value' => '',
1073 ],
1074 ],
1075 ],
1076 'render_type' => 'none',
1077 'dynamic' => [
1078 'active' => true,
1079 ],
1080 ]
1081 );
1082 $this->end_injection();
1083
1084 // Specific Form style controls
1085 $this->start_injection([
1086 'of' => 'form_styles_component_divider',
1087 'at' => 'after',
1088 ]);
1089
1090 $this->add_control(
1091 'heading_html',
1092 [
1093 'label' => esc_html__('HTML Field', 'uicore-elements'),
1094 'type' => Controls_Manager::HEADING,
1095 ]
1096 );
1097 $this->add_control(
1098 'html_spacing',
1099 [
1100 'label' => esc_html__('Spacing', 'uicore-elements'),
1101 'type' => Controls_Manager::SLIDER,
1102 'size_units' => ['px', 'em', 'rem', 'custom'],
1103 'default' => [
1104 'size' => 0,
1105 ],
1106 'range' => [
1107 'px' => [
1108 'max' => 60,
1109 ],
1110 'em' => [
1111 'max' => 6,
1112 ],
1113 'rem' => [
1114 'max' => 6,
1115 ],
1116 ],
1117 'selectors' => [
1118 '{{WRAPPER}} .ui-e-field-type-html' => 'padding-bottom: {{SIZE}}{{UNIT}};',
1119 ],
1120 ]
1121 );
1122 $this->add_control(
1123 'html_color',
1124 [
1125 'label' => esc_html__('Color', 'uicore-elements'),
1126 'type' => Controls_Manager::COLOR,
1127 'selectors' => [
1128 '{{WRAPPER}} .ui-e-field-type-html' => 'color: {{VALUE}};',
1129 ],
1130 ]
1131 );
1132 $this->add_group_control(
1133 Group_Control_Typography::get_type(),
1134 [
1135 'name' => 'html_typography',
1136 'selector' => '{{WRAPPER}} .ui-e-field-type-html',
1137 'global' => [
1138 'default' => Global_Typography::TYPOGRAPHY_TEXT,
1139 ],
1140 ]
1141 );
1142
1143 $this->add_control(
1144 'heading_file',
1145 [
1146 'label' => esc_html__('Upload File Field', 'uicore-elements'),
1147 'type' => Controls_Manager::HEADING,
1148 'separator' => 'before',
1149 ]
1150 );
1151 $this->add_control(
1152 'file_color',
1153 [
1154 'label' => esc_html__('Color', 'uicore-elements'),
1155 'type' => Controls_Manager::COLOR,
1156 'selectors' => [
1157 '{{WRAPPER}} .ui-e-field-type-file input.ui-e-field' => 'color: {{VALUE}};',
1158 ],
1159 'default' => 'var(--e-global-color-uicore_body)',
1160
1161 ]
1162 );
1163 $this->end_injection();
1164 }
1165 function recaptcha_js()
1166 {
1167 ?>
1168 <script>
1169 window.uicore_elements_recaptcha = '<?php echo esc_html(get_option('uicore_elements_recaptcha_site_key')); ?>';
1170 </script>
1171 <?php
1172 }
1173
1174 protected function render()
1175 {
1176
1177 $instance = $this->get_settings_for_display();
1178 $is_recaptcha_required = false;
1179
1180 // Save widget settings so form API can retrieve them
1181 set_transient('ui_e_form_widget_settings_' . $this->get_id(), $instance, DAY_IN_SECONDS);
1182
1183 // Render Form Atts
1184 $this->add_render_attribute(
1185 [
1186 'wrapper' => [
1187 'class' => [
1188 'ui-e-fields-wrp',
1189 ],
1190 ],
1191 'submit-group' => [
1192 'class' => [
1193 'ui-e-field-group',
1194 'elementor-column',
1195 'ui-e-field-type-submit',
1196 ],
1197 ],
1198 'button' => [
1199 'class' => 'elementor-button',
1200 ],
1201 'icon-align' => [
1202 'class' => [
1203 empty($instance['button_icon_align']) ? '' : 'ui-e-icon ui-e-align-' . $instance['button_icon_align'],
1204 ],
1205 ],
1206 ]
1207 );
1208
1209 // Fallback for empty control values
1210 if (empty($instance['button_width'])) {
1211 $instance['button_width'] = '100';
1212 }
1213
1214 // Button atts
1215 $this->add_render_attribute('submit-group', 'class', 'elementor-col-' . $instance['button_width'] . ' e-form__buttons');
1216
1217 if (! empty($instance['button_width_tablet'])) {
1218 $this->add_render_attribute('submit-group', 'class', 'elementor-md-' . $instance['button_width_tablet']);
1219 }
1220 if (! empty($instance['button_width_mobile'])) {
1221 $this->add_render_attribute('submit-group', 'class', 'elementor-sm-' . $instance['button_width_mobile']);
1222 }
1223 if ($instance['button_hover_animation']) {
1224 $this->add_render_attribute('button', 'class', 'elementor-animation-' . $instance['button_hover_animation']);
1225 }
1226
1227 // Form atts
1228 if (! empty($instance['form_id'])) {
1229 $this->add_render_attribute('form', 'id', $instance['form_id']);
1230 }
1231 if (! empty($instance['form_name'])) {
1232 $this->add_render_attribute('form', 'name', $instance['form_name']);
1233 }
1234 if ('no' === $instance['form_validation']) {
1235 $this->add_render_attribute('form', 'novalidate');
1236 }
1237 if (! empty($instance['button_css_id'])) {
1238 $this->add_render_attribute('button', 'id', $instance['button_css_id']);
1239 }
1240
1241 $referer_title = trim(wp_title('', false));
1242 if (! $referer_title && is_home()) {
1243 $referer_title = get_option('blogname');
1244 }
1245
1246 // Get default messages
1247 $messages = Contact_Form_Service::get_default_messages();
1248
1249 // Set frontend validation message
1250 $front_msg_required = isset($instance['required_fields_message'])
1251 ? $instance['required_fields_message']
1252 : $messages['required'];
1253 ?>
1254
1255 <form class="ui-e-form" method="post" <?php $this->print_render_attribute_string('form'); ?>>
1256
1257 <input type="hidden" name="post_id" value="<?php echo esc_attr(get_the_ID()); ?>" />
1258 <input type="hidden" name="widget_type" value="contact-form">
1259
1260 <input type="hidden" name="required_fields_message" value="<?php echo esc_html($front_msg_required); ?>">
1261
1262 <div <?php $this->print_render_attribute_string('wrapper'); ?>>
1263
1264 <?php foreach ($instance['form_fields'] as $item_index => $item) :
1265 $this->form_fields_render_attributes($item_index, $instance, $item);
1266
1267 $field_type = $item['field_type'];
1268
1269 if ($field_type === 'recaptcha' || $field_type === 'recaptcha_v3') {
1270 $is_recaptcha_required = true;
1271 }
1272
1273 $print_label = ! in_array($item['field_type'], ['hidden', 'html'], true);
1274 ?>
1275
1276 <div <?php $this->print_render_attribute_string('field-group' . $item_index); ?>>
1277 <?php
1278 // Print label (excepts if recaptcha)
1279 if ($print_label && $item['field_label'] && $item['field_type'] !== 'recaptcha' && $item['field_type'] !== 'recaptcha_v3') {
1280 ?>
1281 <label <?php $this->print_render_attribute_string('label' . $item_index); ?>>
1282 <?php // PHPCS - the variable $item['field_label'] is safe.
1283 echo $item['field_label']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1284 ?>
1285 </label>
1286 <?php
1287 }
1288
1289 // Print field
1290 switch ($item['field_type']):
1291 case 'html':
1292 echo do_shortcode($item['field_html']);
1293 break;
1294
1295 case 'textarea':
1296 // PHPCS - the method build_textarea_field is safe.
1297 echo $this->build_textarea_field($item, $item_index); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1298 break;
1299
1300 case 'select':
1301 // PHPCS - the method build_select_field is safe.
1302 echo $this->build_select_field($item, $item_index); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1303 break;
1304
1305 case 'acceptance':
1306 // PHPCS - the method build_select_field is safe.
1307 echo $this->build_acceptance_field($item, $item_index); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1308 break;
1309
1310 case 'radio':
1311 case 'checkbox':
1312 // PHPCS - the method build_radio_checkbox_field is safe.
1313 echo $this->build_radio_checkbox_field($item, $item_index, $item['field_type']); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1314 break;
1315
1316 case 'address': // is actually honeypot
1317 // PHPCS - the method build_honeypot_field is safe.
1318 echo $this->build_honeypot_field($item, $item_index); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1319 break;
1320
1321 case 'recaptcha':
1322 // get widget ID
1323 echo '<input type="hidden" name="recaptcha"/> <div id="ui-e-recaptcha-' . esc_attr($this->get_ID()) . '"></div>';
1324 break;
1325
1326 case 'recaptcha_v3':
1327 echo '<input type="hidden" name="recaptcha_v3"/>';
1328 break;
1329
1330 // All other cases are covered by the add_render_atribute()
1331 default:
1332 $this->add_render_attribute('input' . $item_index, 'class', 'ui-e-field-textual');
1333 ?>
1334 <input size="1" <?php $this->print_render_attribute_string('input' . $item_index); ?>>
1335 <?php
1336 break;
1337
1338 endswitch;
1339 ?>
1340 </div>
1341
1342 <?php endforeach; ?>
1343
1344 <div <?php $this->print_render_attribute_string('submit-group'); ?>>
1345 <button type="submit" <?php $this->print_render_attribute_string('button'); ?>>
1346 <span <?php $this->print_render_attribute_string('content-wrapper'); ?>>
1347 <?php if (! empty($instance['button_icon']) || ! empty($instance['selected_button_icon'])) : ?>
1348 <span <?php $this->print_render_attribute_string('icon-align'); ?>>
1349 <?php Icons_Manager::render_icon($instance['selected_button_icon'], ['aria-hidden' => 'true']); ?>
1350 <?php if (empty($instance['button_text'])) : ?>
1351 <span class="elementor-screen-only"><?php echo esc_html__('Submit', 'uicore-elements'); ?></span>
1352 <?php endif; ?>
1353 </span>
1354 <?php endif; ?>
1355 <?php if (! empty($instance['button_text'])) : ?>
1356 <span class="ui-e-text"><?php $this->print_unescaped_setting('button_text'); ?></span>
1357 <?php endif; ?>
1358 </span>
1359 </button>
1360 </div>
1361
1362 </div>
1363
1364 <div class="ui-e-message <?php echo $this->is_edit_mode() ? 'elementor-hidden' : ''; ?>">
1365 <?php if ($this->is_edit_mode()) :
1366 // Get custom messages if set, else use default
1367 $success = isset($instance['success_message'])
1368 ? $instance['success_message']
1369 : $messages['success'];
1370 $error = isset($instance['error_message'])
1371 ? $instance['error_message']
1372 : $messages['error'];
1373 ?>
1374 <span class="success"> <?php echo esc_html($success); ?> </span> <br>
1375 <span class="error"> <?php echo esc_html($error); ?> </span>
1376 <?php endif; ?>
1377 </div>
1378 </form>
1379 <?php
1380
1381 //add js to footer if recaptcha is enabled
1382 if ($is_recaptcha_required) {
1383 add_action('wp_footer', [$this, 'recaptcha_js'], 999);
1384 }
1385
1386 // Add frontend validation messages to js var
1387 ?>
1388 <script>
1389 window.ui_e_form_validation_messages = <?php echo json_encode([
1390 'required_fields' => esc_html($front_msg_required),
1391 ]); ?>;
1392 </script>
1393 <?php
1394 }
1395
1396 /*
1397 protected function content_template() {
1398 ?>
1399 <#
1400 view.addRenderAttribute(
1401 'form',
1402 {
1403 'id': settings.form_id,
1404 'name': settings.form_name,
1405 }
1406 );
1407 if ( 'no' === settings.form_validation ) {
1408 view.addRenderAttribute( 'form', 'novalidate' );
1409 }
1410 #>
1411 <form class="ui-e-form" {{{ view.getRenderAttributeString( 'form' ) }}}>
1412 <div class="ui-e-fields-wrp">
1413 <#
1414 for ( var i in settings.form_fields ) {
1415 var item = settings.form_fields[ i ];
1416 item.field_type = _.escape( item.field_type );
1417 item.field_value = _.escape( item.field_value );
1418
1419 var options = item.field_options ? item.field_options.split( '\n' ) : [],
1420 itemClasses = _.escape( item.css_classes ),
1421 labelVisibility = '',
1422 placeholder = '',
1423 required = '',
1424 checked_by_default = '',
1425 inputField = '',
1426 multiple = '',
1427 fieldGroupClasses = 'ui-e-field-group elementor-column ui-e-field-type-' + item.field_type,
1428 printLabel = settings.show_labels && ! [ 'hidden', 'html', 'recaptcha', 'recaptcha_v3' ].includes( item.field_type );
1429
1430 fieldGroupClasses += ' elementor-col-' + ( ( '' !== item.width ) ? item.width : '100' );
1431
1432 if ( item.width_tablet ) {
1433 fieldGroupClasses += ' elementor-md-' + item.width_tablet;
1434 }
1435
1436 if ( item.width_mobile ) {
1437 fieldGroupClasses += ' elementor-sm-' + item.width_mobile;
1438 }
1439
1440 if ( item.required ) {
1441 required = 'required';
1442 fieldGroupClasses += ' ui-e-field-required';
1443
1444 if ( settings.mark_required ) {
1445 fieldGroupClasses += ' ui-e-required';
1446 }
1447 }
1448
1449 if ( item.placeholder ) {
1450 placeholder = 'placeholder="' + _.escape( item.placeholder ) + '"';
1451 }
1452
1453 if ( item.allow_multiple ) {
1454 multiple = ' multiple';
1455 fieldGroupClasses += ' ui-e-field-type-' + item.field_type + '-multiple';
1456 }
1457
1458 switch ( item.field_type ) {
1459 case 'html':
1460 inputField = item.field_html;
1461 break;
1462
1463 case 'textarea':
1464 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>';
1465 break;
1466
1467 case 'select':
1468 if ( options ) {
1469 var size = '';
1470 if ( item.allow_multiple && item.select_size ) {
1471 size = ' size="' + item.select_size + '"';
1472 }
1473 inputField = '<div class="ui-e-field ui-e-field-select ui-e-field-subgroup' + itemClasses + '">';
1474 inputField += '<select class="ui-e-field-textual" name="form_field_' + i + '" id="form_field_' + i + '" ' + required + multiple + size + ' >';
1475 for ( var x in options ) {
1476 var option_value = options[ x ];
1477 var option_label = options[ x ];
1478 var option_id = 'form_field_option' + i + x;
1479
1480 if ( options[ x ].indexOf( '|' ) > -1 ) {
1481 var label_value = options[ x ].split( '|' );
1482 option_label = label_value[0];
1483 option_value = label_value[1];
1484 }
1485
1486 view.addRenderAttribute( option_id, 'value', option_value );
1487 if ( item.field_value.split( ',' ) .indexOf( option_value ) ) {
1488 view.addRenderAttribute( option_id, 'selected', 'selected' );
1489 }
1490 inputField += '<option ' + view.getRenderAttributeString( option_id ) + '>' + option_label + '</option>';
1491 }
1492 inputField += '</select></div>';
1493 }
1494 break;
1495
1496 case 'radio':
1497 case 'checkbox':
1498 if ( options ) {
1499 var multiple = '';
1500
1501 if ( 'checkbox' === item.field_type && options.length > 1 ) {
1502 multiple = '[]';
1503 }
1504
1505 inputField = '<div class="ui-e-field-subgroup ' + itemClasses + ' ' + _.escape( item.inline_list ) + '">';
1506
1507 for ( var x in options ) {
1508 var option_value = options[ x ];
1509 var option_label = options[ x ];
1510 var option_id = 'form_field_' + item.field_type + i + x;
1511 if ( options[x].indexOf( '|' ) > -1 ) {
1512 var label_value = options[x].split( '|' );
1513 option_label = label_value[0];
1514 option_value = label_value[1];
1515 }
1516
1517 view.addRenderAttribute( option_id, {
1518 value: option_value,
1519 type: item.field_type,
1520 id: 'form_field_' + i + '-' + x,
1521 name: 'form_field_' + i + multiple
1522 } );
1523
1524 if ( option_value === item.field_value ) {
1525 view.addRenderAttribute( option_id, 'checked', 'checked' );
1526 }
1527
1528 inputField += '<span class="ui-e-field-option"><input ' + view.getRenderAttributeString( option_id ) + ' ' + required + '> ';
1529 inputField += '<label for="form_field_' + i + '-' + x + '">' + option_label + '</label></span>';
1530
1531 }
1532
1533 inputField += '</div>';
1534 }
1535 break;
1536
1537 case 'acceptance' :
1538 var checked = '';
1539 if(item.checked_by_default == 'yes') {
1540 checked = ' checked';
1541 }
1542 inputField += '<div class="ui-e-field-subgroup">';
1543 inputField += '<input type="checkbox" class="ui-e-field ui-e-acceptance-field" name="form_field_' + i + '" id="form_field_' + i + '" ' + required + checked + '>';
1544 inputField += '<label for="form_field_' + i + '">' + item.acceptance_text + '</label>';
1545 inputField += '</div>';
1546 break;
1547
1548 case 'recaptcha' :
1549 case 'recaptcha_v3' :
1550 inputField = '<input type="hidden" name="recaptcha"/> <div id="ui-e-recaptcha"></div>';
1551 break;
1552
1553 default:
1554 itemClasses = 'ui-e-field-textual ' + itemClasses;
1555 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 + ' >';
1556 break;
1557 }
1558
1559 if ( inputField ) {
1560 #>
1561 <div class="{{ fieldGroupClasses }}">
1562
1563 <# if ( printLabel && item.field_label ) { #>
1564 <label class="ui-e-field-label" for="form_field_{{ i }}" {{{ labelVisibility }}}>{{{ item.field_label }}}</label>
1565 <# } #>
1566
1567 {{{ inputField }}}
1568 </div>
1569 <#
1570 }
1571 }
1572
1573
1574 var buttonClasses = 'ui-e-field-group elementor-column ui-e-field-type-submit e-form__buttons';
1575
1576 buttonClasses += ' elementor-col-' + ( ( '' !== settings.button_width ) ? settings.button_width : '100' );
1577
1578 if ( settings.button_width_tablet ) {
1579 buttonClasses += ' elementor-md-' + settings.button_width_tablet;
1580 }
1581
1582 if ( settings.button_width_mobile ) {
1583 buttonClasses += ' elementor-sm-' + settings.button_width_mobile;
1584 }
1585
1586 var iconHTML = elementor.helpers.renderIcon( view, settings.selected_button_icon, { 'aria-hidden': true }, 'i' , 'object' )
1587 #>
1588
1589 <div class="{{ buttonClasses }}">
1590 <button id="{{ settings.button_css_id }}" type="submit" class="elementor-button elementor-animation-{{ settings.button_hover_animation }}">
1591 <span>
1592 <# if ( settings.button_icon || settings.selected_button_icon ) { #>
1593 <span class="ui-e-icon ui-e-align-{{ settings.button_icon_align }}">
1594 <# if ( iconHTML && iconHTML.rendered && ( ! settings.button_icon ) ) { #>
1595 {{{ iconHTML.value }}}
1596 <# } else { #>
1597 <i class="{{ settings.button_icon }}" aria-hidden="true"></i>
1598 <# } #>
1599 <span class="elementor-screen-only"><?php echo esc_html__( 'Submit', 'uicore-elements' ); ?></span>
1600 </span>
1601 <# } #>
1602
1603 <# if ( settings.button_text ) { #>
1604 <span class="ui-e-text">{{{ settings.button_text }}}</span>
1605 <# } #>
1606 </span>
1607 </button>
1608 </div>
1609 </div>
1610 <div class="ui-e-message elementor-hidden">
1611 <#
1612 const success = settings.success_message;
1613 const error = settings.error_message;
1614 #>
1615 <span class="success">{{{ success }}}</span> <br>
1616 <span class="error">{{{ error }}}</span>
1617 </div>
1618 </form>
1619 <?php
1620 }
1621 */
1622 }
1623 \Elementor\Plugin::instance()->widgets_manager->register(new ContactForm());
1624