PluginProbe
UiCore Elements – Free widgets and templates for Elementor / 1.3.18
UiCore Elements – Free widgets and templates for Elementor v1.3.18
1.3.18 1.3.17 1.3.16 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.2.0 1.2.1 1.2.2 1.2.3 All 42 releases
← All changes | includes/widgets/contact-form.php +1131 -2154 1.0.5 → 1.3.18 View file →
@@ -1,9 +1,13 @@
1 1 <?php
2 +
2 3 namespace UiCoreElements;
3 4
4 5 use UiCoreElements\Helper;
5 6 use UiCoreElements\Utils\Contact_Form_Service;
7 +use UiCoreElements\Utils\Form_Component;
8 +use UiCoreElements\Utils\Newsletter_Services;
9 +
6 10 use Elementor\Controls_Manager;
7 11 use Elementor\Icons_Manager;
8 12 use Elementor\Utils;
9 13 use Elementor\Repeater;
@@ -21,28 +25,35 @@
21 25 * @author Lucas Marini Falbo <[email protected]>
22 26 * @since 1.0.5
23 27 */
24 28
25 -class ContactForm extends UiCoreWidget {
29 +class ContactForm extends UiCoreWidget
30 +{
26 31
27 - public function get_name() {
28 - return 'uicore-contact-form';
29 - }
32 + use Form_Component;
30 33
31 - public function get_title() {
32 - return __( 'Contact Form', 'uicore-elements' );
33 - }
34 + public function get_name()
35 + {
36 + return 'uicore-contact-form';
37 + }
34 38
35 - public function get_icon() {
36 - return 'eicon-form-horizontal ui-e-widget';
37 - }
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 + }
38 48 public function get_categories()
39 49 {
40 50 return ['uicore'];
41 51 }
42 - public function get_keywords() {
43 - return [ 'form', 'forms', 'contact', 'mail', 'send', 'field', 'button', 'recaptcha', ];
44 - }
52 + public function get_keywords()
53 + {
54 + return ['form', 'forms', 'contact', 'mail', 'send', 'field', 'button', 'recaptcha',];
55 + }
45 56 public function get_styles()
46 57 {
47 58 return ['contact-form'];
48 59 }
@@ -57,21 +68,26 @@
57 68 'custom_condition' => $this->check_recaptcha_version('v3')
58 69 ],
59 70 'repeater-custom-key' => [
60 71 'custom_condition' => $this->is_edit_mode()
61 - ]
72 + ]
62 73 ];
63 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 + }
64 80 function check_recaptcha_version($version)
65 81 {
66 82
67 - if($this->is_edit_mode()){
83 + if ($this->is_edit_mode()) {
68 84 return true;
69 85 }
70 86 $settings = $this->get_settings_for_display();
71 87 foreach ($settings['form_fields'] as $field) {
72 88 $version_to_check = $version === 'v2' ? 'recaptcha' : 'recaptcha_v3';
73 - if($field['field_type'] === $version_to_check){
89 + if ($field['field_type'] === $version_to_check) {
74 90 return true;
75 91 }
76 92 }
77 93 return false;
@@ -76,854 +92,696 @@
76 92 }
77 93 return false;
78 94 }
79 95
80 - // Helper Functions
81 - function get_field_types()
96 + // Helper Functions
97 + function get_field_types()
82 98 {
83 99 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 - ];
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 + ];
104 120 }
105 121
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 - }
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 + {
116 132
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 - );
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 + }
137 138
138 - /* translators: %s: Site title. */
139 - $default_message = sprintf( html_entity_decode( esc_html__( 'New message from "%s"', 'uicore-elements' ) ), get_option( 'blogname' ) );
139 + // Default method
140 + $this->add_render_attribute($element, 'required', 'required');
141 + $this->add_render_attribute($element, 'aria-required', 'true');
142 + }
140 143
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 144 // 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',
145 + function build_honeypot_field($item, $item_index)
146 + {
147 + $this->add_render_attribute('honeypot' . $item_index, [
148 + 'class' => [
149 + 'ui-e-field',
308 150 'ui-e-h-p',
309 - esc_attr( $item['css_classes'] ),
310 - ],
311 - 'name' => 'ui-e-h-p',
312 - 'id' => 'ui-e-h-p',
313 - ] );
151 + esc_attr($item['css_classes']),
152 + ],
153 + 'name' => 'ui-e-h-p',
154 + 'id' => 'ui-e-h-p',
155 + 'autocomplete' => 'off',
156 + ]);
314 157
315 - if ( $item['placeholder'] ) {
316 - $this->add_render_attribute( 'honeypot' . $item_index, 'placeholder', $item['placeholder'] );
317 - }
158 + if ($item['placeholder']) {
159 + $this->add_render_attribute('honeypot' . $item_index, 'placeholder', $item['placeholder']);
160 + }
318 161
319 - if ( $item['required'] ) {
320 - $this->add_required_attribute( 'honeypot' . $item_index );
321 - }
162 + if ($item['required']) {
163 + $this->add_required_attribute('honeypot' . $item_index);
164 + }
322 165
323 - $value = empty( $item['field_value'] ) ? '' : $item['field_value'];
166 + $value = empty($item['field_value']) ? '' : $item['field_value'];
324 167
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 - ] );
168 + return '<input ' . $this->get_render_attribute_string('honeypot' . $item_index) . ' tabindex="-1">' . esc_html($value) . '</input>';
169 + }
170 + function build_textarea_field($item, $item_index)
171 + {
172 + $this->add_render_attribute('textarea' . $item_index, [
173 + 'class' => [
174 + 'ui-e-field',
175 + esc_attr($item['css_classes']),
176 + ],
177 + 'name' => $this->get_attribute_name($item),
178 + 'id' => $this->get_attribute_id($item),
179 + 'rows' => $item['rows'],
180 + ]);
337 181
338 - if ( $item['placeholder'] ) {
339 - $this->add_render_attribute( 'textarea' . $item_index, 'placeholder', $item['placeholder'] );
340 - }
182 + if ($item['placeholder']) {
183 + $this->add_render_attribute('textarea' . $item_index, 'placeholder', $item['placeholder']);
184 + }
341 185
342 - if ( $item['required'] ) {
343 - $this->add_required_attribute( 'textarea' . $item_index );
344 - }
186 + if ($item['required']) {
187 + $this->add_required_attribute('textarea' . $item_index);
188 + }
345 189
346 - $value = empty( $item['field_value'] ) ? '' : $item['field_value'];
190 + $value = empty($item['field_value']) ? '' : $item['field_value'];
347 191
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',
192 + return '<textarea ' . $this->get_render_attribute_string('textarea' . $item_index) . '>' . esc_textarea($value) . '</textarea>';
193 + }
194 + function build_select_field($item, $i)
195 + {
196 + $this->add_render_attribute(
197 + [
198 + 'select-wrapper' . $i => [
199 + 'class' => [
200 + 'ui-e-field',
201 + 'ui-e-field-select',
357 202 '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 - );
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 + );
370 215
371 - if ( $item['required'] ) {
372 - $this->add_required_attribute( 'select' . $i );
373 - }
216 + if ($item['required']) {
217 + $this->add_required_attribute('select' . $i);
218 + }
374 219
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 - }
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 + }
381 226
382 - $options = preg_split( "/\\r\\n|\\r|\\n/", $item['field_options'] );
227 + $options = preg_split("/\\r\\n|\\r|\\n/", $item['field_options']);
383 228
384 - if ( ! $options ) {
385 - return '';
386 - }
229 + if (! $options) {
230 + return '';
231 + }
387 232
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 );
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);
397 242
398 - if ( false !== strpos( $option, '|' ) ) {
399 - list( $label, $value ) = explode( '|', $option );
400 - $option_value = esc_attr( $value );
401 - $option_label = esc_html( $label );
402 - }
243 + if (false !== strpos($option, '|')) {
244 + list($label, $value) = explode('|', $option);
245 + $option_value = esc_attr($value);
246 + $option_label = esc_html($label);
247 + }
403 248
404 - $this->add_render_attribute( $option_id, 'value', $option_value );
249 + $this->add_render_attribute($option_id, 'value', $option_value);
405 250
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
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
417 263
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 - }
264 + $select = ob_get_clean();
265 + return $select;
266 + }
267 + function build_radio_checkbox_field($item, $item_index, $type)
268 + {
269 + $options = preg_split("/\\r\\n|\\r|\\n/", $item['field_options']);
270 + $html = '';
271 + if ($options) {
272 + $html .= '<div class="ui-e-field-subgroup ' . esc_attr($item['css_classes']) . ' ' . esc_attr($item['inline_list']) . '">';
273 + foreach ($options as $key => $option) {
274 + $element_id = $item['custom_id'] . $key;
275 + $html_id = $this->get_attribute_id($item) . '-' . $key;
276 + $option_label = $option;
277 + $option_value = $option;
278 + if (false !== strpos($option, '|')) {
279 + list($option_label, $option_value) = explode('|', $option);
280 + }
434 281
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 - );
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 + );
444 291
445 - if ( ! empty( $item['field_value'] ) && $option_value === $item['field_value'] ) {
446 - $this->add_render_attribute( $element_id, 'checked', 'checked' );
447 - }
292 + if ($item['required']) {
293 + $this->add_required_attribute($element_id, true);
294 + }
448 295
449 - if ( $item['required'] && 'radio' === $type ) {
450 - $this->add_required_attribute( $element_id );
451 - }
296 + if (! empty($item['field_value']) && $option_value === $item['field_value']) {
297 + $this->add_render_attribute($element_id, 'checked', 'checked');
298 + }
452 299
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 - }
300 + if ($item['required'] && 'radio' === $type) {
301 + $this->add_required_attribute($element_id);
302 + }
457 303
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 );
304 + $html .= '<span class="ui-e-field-option">';
305 + $html .= '<input ' . $this->get_render_attribute_string($element_id) . '>';
306 + $html .= '<label for="' . $html_id . '">';
307 + $html .= esc_html($option_label);
308 + $html .= '</label></span>';
309 + }
310 + $html .= '</div>';
311 + }
464 312
465 - if ( ! empty( $item['acceptance_text'] ) ) {
466 - $text = '<label for="' . $this->get_attribute_id( $item ) . '">' . $item['acceptance_text'] . '</label>';
467 - }
313 + return $html;
314 + }
315 + function build_acceptance_field($item, $item_index)
316 + {
317 + $text = '';
318 + $this->add_render_attribute('input' . $item_index, 'class', 'ui-e-acceptance-field');
319 + $this->add_render_attribute('input' . $item_index, 'type', 'checkbox', true);
468 320
469 - if ( ! empty( $item['checked_by_default'] ) ) {
470 - $this->add_render_attribute( 'input' . $item_index, 'checked', 'checked' );
471 - }
321 + if (! empty($item['acceptance_text'])) {
322 + $text = '<label for="' . $this->get_attribute_id($item) . '">' . Helper::esc_string($item['acceptance_text']) . '</label>';
323 + }
472 324
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 - );
325 + if (! empty($item['checked_by_default'])) {
326 + $this->add_render_attribute('input' . $item_index, 'checked', 'checked');
327 + }
507 328
508 - if ( empty( $item['width'] ) ) {
509 - $item['width'] = '100';
510 - }
329 + ?>
330 + <div class="ui-e-field-subgroup <?php echo esc_attr($item['css_classes']); ?>">
331 + <input <?php $this->print_render_attribute_string('input' . $item_index); ?>>
332 + <?php // PHPCS - the variables $text is safe.
333 + echo $text; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
334 + ?>
335 + </div>
336 + <?php
337 + }
338 + function form_fields_render_attributes($i, $instance, $item)
339 + {
340 + $this->add_render_attribute(
341 + [
342 + 'field-group' . $i => [
343 + 'class' => [
344 + 'ui-e-field-type-' . $item['field_type'],
345 + 'ui-e-field-group',
346 + 'elementor-column',
347 + 'ui-e-field-group-' . $item['custom_id'],
348 + ],
349 + ],
350 + 'input' . $i => [
351 + 'type' => $item['field_type'],
352 + 'name' => $this->get_attribute_name($item),
353 + 'id' => $this->get_attribute_id($item),
354 + 'class' => [
355 + 'ui-e-field',
356 + empty($item['css_classes']) ? '' : esc_attr($item['css_classes']),
357 + ],
358 + ],
359 + 'label' . $i => [
360 + 'for' => $this->get_attribute_id($item),
361 + 'class' => 'ui-e-label',
362 + ],
363 + ]
364 + );
511 365
512 - $this->add_render_attribute( 'field-group' . $i, 'class', 'elementor-col-' . $item['width'] );
366 + if (empty($item['width'])) {
367 + $item['width'] = '100';
368 + }
513 369
514 - if ( ! empty( $item['width_tablet'] ) ) {
515 - $this->add_render_attribute( 'field-group' . $i, 'class', 'elementor-md-' . $item['width_tablet'] );
516 - }
370 + $this->add_render_attribute('field-group' . $i, 'class', 'elementor-col-' . $item['width']);
517 371
518 - if ( $item['allow_multiple'] ) {
519 - $this->add_render_attribute( 'field-group' . $i, 'class', 'ui-e-field-type-' . $item['field_type'] . '-multiple' );
520 - }
372 + if (! empty($item['width_tablet'])) {
373 + $this->add_render_attribute('field-group' . $i, 'class', 'elementor-md-' . $item['width_tablet']);
374 + }
521 375
522 - if ( ! empty( $item['width_mobile'] ) ) {
523 - $this->add_render_attribute( 'field-group' . $i, 'class', 'elementor-sm-' . $item['width_mobile'] );
524 - }
376 + if ($item['allow_multiple']) {
377 + $this->add_render_attribute('field-group' . $i, 'class', 'ui-e-field-type-' . $item['field_type'] . '-multiple');
378 + }
525 379
526 - // Allow zero as placeholder.
527 - if ( ! Utils::is_empty( $item['placeholder'] ) ) {
528 - $this->add_render_attribute( 'input' . $i, 'placeholder', $item['placeholder'] );
529 - }
380 + if (! empty($item['width_mobile'])) {
381 + $this->add_render_attribute('field-group' . $i, 'class', 'elementor-sm-' . $item['width_mobile']);
382 + }
530 383
531 - if ( ! empty( $item['field_value'] ) ) {
532 - $this->add_render_attribute( 'input' . $i, 'value', $item['field_value'] );
533 - }
384 + // Allow zero as placeholder.
385 + if (! Utils::is_empty($item['placeholder'])) {
386 + $this->add_render_attribute('input' . $i, 'placeholder', $item['placeholder']);
387 + }
534 388
535 - if ( ! $instance['show_labels'] ) {
536 - $this->add_render_attribute( 'label' . $i, 'class', 'elementor-screen-only' );
537 - }
389 + if (! empty($item['field_value'])) {
390 + $this->add_render_attribute('input' . $i, 'value', $item['field_value']);
391 + }
538 392
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 - }
393 + if (! $instance['show_labels']) {
394 + $this->add_render_attribute('label' . $i, 'class', 'elementor-screen-only');
395 + }
548 396
549 - protected function register_controls() {
397 + if (! empty($item['required'])) {
398 + $class = '';
399 + if (! empty($instance['mark_required'])) {
400 + $class .= ' ui-e-required';
401 + }
402 + $this->add_render_attribute('field-group' . $i, 'class', $class);
403 + $this->add_required_attribute('input' . $i);
404 + }
405 + }
550 406
407 + protected function register_controls()
408 + {
409 +
551 410 // Content Controls
552 411 // Repeater Controls used by `form_fields` control
553 412 $repeater = new Repeater();
554 - $repeater->start_controls_tabs( 'form_fields_tabs' );
413 + $repeater->start_controls_tabs('form_fields_tabs');
555 414
556 - $repeater->start_controls_tab(
557 - 'form_fields_content_tab',
558 - [
559 - 'label' => esc_html__( 'Content', 'uicore-elements' ),
560 - ]
561 - );
415 + $repeater->start_controls_tab(
416 + 'form_fields_content_tab',
417 + [
418 + 'label' => esc_html__('Content', 'uicore-elements'),
419 + ]
420 + );
562 421
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 - ],
422 + $repeater->add_control(
423 + 'field_type',
424 + [
425 + 'label' => esc_html__('Type', 'uicore-elements'),
426 + 'type' => Controls_Manager::SELECT,
427 + 'options' => $this->get_field_types(),
428 + 'default' => 'text',
429 + ]
430 + );
431 + $repeater->add_control(
432 + 'field_label',
433 + [
434 + 'label' => esc_html__('Label', 'uicore-elements'),
435 + 'type' => Controls_Manager::TEXT,
436 + 'default' => '',
437 + 'dynamic' => [
438 + 'active' => true,
439 + ],
440 + ]
441 + );
442 + $repeater->add_control(
443 + 'placeholder',
444 + [
445 + 'label' => esc_html__('Placeholder', 'uicore-elements'),
446 + 'type' => Controls_Manager::TEXT,
447 + 'default' => '',
448 + 'conditions' => [
449 + 'terms' => [
450 + [
451 + 'name' => 'field_type',
452 + 'operator' => 'in',
453 + 'value' => [
454 + 'tel',
455 + 'text',
456 + 'email',
457 + 'textarea',
458 + 'number',
459 + 'url',
460 + 'password',
604 461 ],
605 462 ],
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 - ],
463 + ],
464 + ],
465 + 'dynamic' => [
466 + 'active' => true,
467 + ],
468 + ]
469 + );
470 + $repeater->add_control(
471 + 'required',
472 + [
473 + 'label' => esc_html__('Required', 'uicore-elements'),
474 + 'type' => Controls_Manager::SWITCHER,
475 + 'return_value' => 'true',
476 + 'default' => '',
477 + 'conditions' => [
478 + 'terms' => [
479 + [
480 + 'name' => 'field_type',
481 + 'operator' => '!in',
482 + 'value' => [
483 + 'recaptcha',
484 + 'recaptcha_v3',
485 + 'hidden',
486 + 'html',
631 487 ],
632 488 ],
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 - ],
489 + ],
490 + ],
491 + ]
492 + );
493 + $repeater->add_control(
494 + 'field_options',
495 + [
496 + 'label' => esc_html__('Options', 'uicore-elements'),
497 + 'type' => Controls_Manager::TEXTAREA,
498 + 'default' => '',
499 + 'description' => esc_html__('Enter each option in a separate line. To differentiate between label and value, separate them with a pipe char ("|"). For example: First Name|f_name', 'uicore-elements'),
500 + 'conditions' => [
501 + 'terms' => [
502 + [
503 + 'name' => 'field_type',
504 + 'operator' => 'in',
505 + 'value' => [
506 + 'select',
507 + 'checkbox',
508 + 'radio',
653 509 ],
654 510 ],
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 - ],
511 + ],
512 + ],
513 + ]
514 + );
515 + $repeater->add_control(
516 + 'allow_multiple',
517 + [
518 + 'label' => esc_html__('Multiple Selection', 'uicore-elements'),
519 + 'type' => Controls_Manager::SWITCHER,
520 + 'return_value' => 'true',
521 + 'conditions' => [
522 + 'terms' => [
523 + [
524 + 'name' => 'field_type',
525 + 'value' => 'select',
670 526 ],
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 - ],
527 + ],
528 + ],
529 + ]
530 + );
531 + $repeater->add_control(
532 + 'select_size',
533 + [
534 + 'label' => esc_html__('Rows', 'uicore-elements'),
535 + 'type' => Controls_Manager::NUMBER,
536 + 'min' => 2,
537 + 'step' => 1,
538 + 'conditions' => [
539 + 'terms' => [
540 + [
541 + 'name' => 'field_type',
542 + 'value' => 'select',
691 543 ],
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 - ],
544 + [
545 + 'name' => 'allow_multiple',
546 + 'value' => 'true',
712 547 ],
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 - ],
548 + ],
549 + ],
550 + ]
551 + );
552 + $repeater->add_control(
553 + 'inline_list',
554 + [
555 + 'label' => esc_html__('Inline List', 'uicore-elements'),
556 + 'type' => Controls_Manager::SWITCHER,
557 + 'return_value' => 'ui-e-subgroup-inline',
558 + 'default' => '',
559 + 'conditions' => [
560 + 'terms' => [
561 + [
562 + 'name' => 'field_type',
563 + 'operator' => 'in',
564 + 'value' => [
565 + 'checkbox',
566 + 'radio',
729 567 ],
730 568 ],
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%',
569 + ],
570 + ],
571 + ]
572 + );
573 + $repeater->add_control(
574 + 'field_html',
575 + [
576 + 'label' => esc_html__('HTML', 'uicore-elements'),
577 + 'type' => Controls_Manager::TEXTAREA,
578 + 'dynamic' => [
579 + 'active' => true,
580 + ],
581 + 'conditions' => [
582 + 'terms' => [
583 + [
584 + 'name' => 'field_type',
585 + 'value' => 'html',
772 586 ],
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 - ],
587 + ],
588 + ],
589 + ]
590 + );
591 + $repeater->add_control(
592 + 'acceptance_text',
593 + [
594 + 'label' => esc_html__('Acceptance Text', 'uicore-elements'),
595 + 'type' => Controls_Manager::TEXTAREA,
596 + 'condition' => [
597 + 'field_type' => 'acceptance',
598 + ],
599 + ],
600 + );
601 + $repeater->add_control(
602 + 'checked_by_default',
603 + [
604 + 'label' => esc_html__('Checked by Default', 'uicore-elements'),
605 + 'type' => Controls_Manager::SWITCHER,
606 + 'condition' => [
607 + 'field_type' => 'acceptance',
608 + ],
609 + ],
610 + );
611 + $repeater->add_responsive_control(
612 + 'width',
613 + [
614 + 'label' => esc_html__('Column Width', 'uicore-elements'),
615 + 'type' => Controls_Manager::SELECT,
616 + 'options' => [
617 + '' => esc_html__('Default', 'uicore-elements'),
618 + '100' => '100%',
619 + '80' => '80%',
620 + '75' => '75%',
621 + '70' => '70%',
622 + '66' => '66%',
623 + '60' => '60%',
624 + '50' => '50%',
625 + '40' => '40%',
626 + '33' => '33%',
627 + '30' => '30%',
628 + '25' => '25%',
629 + '20' => '20%',
630 + ],
631 + 'default' => '100',
632 + 'conditions' => [
633 + 'terms' => [
634 + [
635 + 'name' => 'field_type',
636 + 'operator' => '!in',
637 + 'value' => [
638 + 'hidden',
639 + 'recaptcha',
640 + 'recaptcha_v3'
785 641 ],
786 642 ],
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 - ],
643 + ],
644 + ],
645 + ]
646 + );
647 + $repeater->add_control(
648 + 'rows',
649 + [
650 + 'label' => esc_html__('Rows', 'uicore-elements'),
651 + 'type' => Controls_Manager::NUMBER,
652 + 'default' => 4,
653 + 'conditions' => [
654 + 'terms' => [
655 + [
656 + 'name' => 'field_type',
657 + 'value' => 'textarea',
802 658 ],
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 - );
659 + ],
660 + ],
661 + ]
662 + );
663 + $repeater->add_control(
664 + 'recaptcha_hide',
665 + [
666 + 'label' => esc_html__('Badge', 'uicore-elements'),
667 + 'type' => Controls_Manager::SELECT,
668 + 'default' => 'hidden',
669 + 'options' => [
670 + 'hidden' => esc_html__('Hidden', 'uicore-elements'),
671 + 'visible' => esc_html__('Visible', 'uicore-elements')
672 + ],
673 + 'condition' => [
674 + 'field_type' => 'recaptcha_v3',
675 + ],
676 + 'selectors' => [
677 + '.grecaptcha-badge' => 'visibility: {{VALUE}};',
678 + ],
679 + ]
680 + );
681 + $recaptcha_keys = (!get_option('uicore_elements_recaptcha_secret_key') && !get_option('uicore_elements_recaptcha_site_key')) ? true : false; // Check if recaptcha API keys were set
682 + $repeater->add_control(
683 + 'recaptcha_warning',
684 + [
685 + 'type' => Controls_Manager::ALERT,
686 + 'alert_type' => 'warning',
687 + 'dismissible' => false,
688 + 'heading' => esc_html__("You haven't set your reCAPTCHA API keys yet.", 'uicore-elements'),
689 + 'content' => Helper::get_admin_settings_url(esc_html__("Click here to configure your API keys.", 'uicore-elements')),
690 + 'condition' => [
691 + 'field_type' => $recaptcha_keys ? ['recaptcha', 'recaptcha_v3'] : [],
692 + ]
693 + ]
694 + );
837 695
838 - $repeater->end_controls_tab();
696 + $repeater->end_controls_tab();
839 697
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 - );
698 + $repeater->start_controls_tab(
699 + 'form_fields_advanced_tab',
700 + [
701 + 'label' => esc_html__('Advanced', 'uicore-elements'),
702 + 'condition' => [
703 + 'field_type!' => ['html', 'address'],
704 + ],
705 + ]
706 + );
849 707
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 - ],
708 + $repeater->add_control(
709 + 'field_value',
710 + [
711 + 'label' => esc_html__('Default Value', 'uicore-elements'),
712 + 'type' => Controls_Manager::TEXT,
713 + 'default' => '',
714 + 'dynamic' => [
715 + 'active' => true,
716 + ],
717 + 'ai' => [
718 + 'active' => false,
719 + ],
720 + 'conditions' => [
721 + 'terms' => [
722 + [
723 + 'name' => 'field_type',
724 + 'operator' => 'in',
725 + 'value' => [
726 + 'text',
727 + 'email',
728 + 'textarea',
729 + 'url',
730 + 'tel',
731 + 'radio',
732 + 'select',
733 + 'number',
734 + 'date',
735 + 'time',
736 + 'hidden',
881 737 ],
882 738 ],
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 - );
739 + ],
740 + ],
741 + ]
742 + );
743 + $repeater->add_control(
744 + 'custom_id',
745 + [
746 + 'label' => esc_html__('ID', 'uicore-elements'),
747 + 'type' => Controls_Manager::TEXT,
748 + 'description' => esc_html__('Please make sure the ID is unique and not used elsewhere in this form. This field allows `A-z 0-9` & underscore chars without spaces.', 'uicore-elements'),
749 + 'render_type' => 'none',
750 + 'required' => true,
751 + 'dynamic' => [
752 + 'active' => true,
753 + ],
754 + 'ai' => [
755 + 'active' => false,
756 + ],
757 + ]
758 + );
759 + $repeater->add_control(
760 + 'css_classes',
761 + [
762 + 'label' => esc_html__('Custom Class', 'uicore-elements'),
763 + 'type' => Controls_Manager::TEXT,
764 + 'default' => '',
765 + 'ai' => [
766 + 'active' => false,
767 + ],
768 + 'placeholder' => esc_html__('e.g: my-class', 'uicore-elements'),
769 + ]
770 + );
771 + $shortcode_template = '{{ view.container.settings.get( \'custom_id\' ) }}';
772 + $repeater->add_control(
773 + 'shortcode',
774 + [
775 + 'label' => esc_html__('Shortcode', 'uicore-elements'),
776 + 'type' => Controls_Manager::RAW_HTML,
777 + 'classes' => 'forms-field-shortcode',
778 + 'raw' => '<input class="elementor-form-field-shortcode" value=\'[field id="' . $shortcode_template . '"]\' readonly />',
779 + 'label_block' => false,
780 + ]
781 + );
924 782
925 - $repeater->end_controls_tab();
783 + $repeater->end_controls_tab();
926 784
927 785 $repeater->end_controls_tabs();
928 786
929 787 $this->start_controls_section(
@@ -928,266 +786,243 @@
928 786
929 787 $this->start_controls_section(
930 788 'section_form_fields',
931 789 [
932 - 'label' => esc_html__( 'Form Fields', 'uicore-elements' ),
790 + 'label' => esc_html__('Form Fields', 'uicore-elements'),
933 791 ]
934 792 );
935 793
936 794
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 - ],
795 + $this->add_control(
796 + 'form_name',
797 + [
798 + 'label' => esc_html__('Form Name', 'uicore-elements'),
799 + 'type' => Controls_Manager::TEXT,
800 + 'default' => esc_html__('New Form', 'uicore-elements'),
801 + 'placeholder' => esc_html__('Form Name', 'uicore-elements'),
802 + ]
803 + );
804 + $this->add_control(
805 + 'form_fields',
806 + [
807 + 'type' => Controls_Manager::REPEATER,
808 + 'fields' => $repeater->get_controls(),
809 + 'default' => [
810 + [
811 + 'custom_id' => 'name',
812 + 'field_type' => 'text',
813 + 'field_label' => esc_html__('Name', 'uicore-elements'),
814 + 'placeholder' => esc_html__('Name', 'uicore-elements'),
815 + 'width' => '100',
816 + 'dynamic' => [
817 + 'active' => true,
961 818 ],
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 819 ],
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!' => '',
820 + [
821 + 'custom_id' => 'email',
822 + 'field_type' => 'email',
823 + 'required' => 'true',
824 + 'field_label' => esc_html__('Email', 'uicore-elements'),
825 + 'placeholder' => esc_html__('Email', 'uicore-elements'),
826 + 'width' => '100',
1011 827 ],
1012 - ]
1013 - );
828 + [
829 + 'custom_id' => 'address',
830 + 'field_type' => 'address',
831 + 'field_label' => esc_html__('address (honeypot)', 'uicore-elements'),
832 + 'placeholder' => esc_html__('address', 'uicore-elements'),
833 + 'width' => '100',
834 + ],
835 + [
836 + 'custom_id' => 'message',
837 + 'field_type' => 'textarea',
838 + 'field_label' => esc_html__('Message', 'uicore-elements'),
839 + 'placeholder' => esc_html__('Message', 'uicore-elements'),
840 + 'width' => '100',
841 + ],
842 + ],
843 + 'title_field' => '{{ field_label }}',
844 + ]
845 + );
846 + $this->add_control(
847 + 'show_labels',
848 + [
849 + 'label' => esc_html__('Label', 'uicore-elements'),
850 + 'type' => Controls_Manager::SWITCHER,
851 + 'label_on' => esc_html__('Show', 'uicore-elements'),
852 + 'label_off' => esc_html__('Hide', 'uicore-elements'),
853 + 'return_value' => 'true',
854 + 'default' => 'true',
855 + 'separator' => 'before',
856 + ]
857 + );
858 + $this->add_control(
859 + 'mark_required',
860 + [
861 + 'label' => esc_html__('Required Mark', 'uicore-elements'),
862 + 'type' => Controls_Manager::SWITCHER,
863 + 'label_on' => esc_html__('Show', 'uicore-elements'),
864 + 'label_off' => esc_html__('Hide', 'uicore-elements'),
865 + 'default' => '',
866 + 'render_type' => 'template',
867 + 'condition' => [
868 + 'show_labels!' => '',
869 + ],
870 + ]
871 + );
1014 872
1015 873 $this->end_controls_section();
1016 874
1017 - $this->start_controls_section(
875 + $this->start_controls_section(
1018 876 'section_buttons',
1019 877 [
1020 - 'label' => esc_html__( 'Button', 'uicore-elements' ),
878 + 'label' => esc_html__('Button', 'uicore-elements'),
1021 879 ]
1022 880 );
1023 881
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%',
882 + $this->add_responsive_control(
883 + 'button_width',
884 + [
885 + 'label' => esc_html__('Column Width', 'uicore-elements'),
886 + 'type' => Controls_Manager::SELECT,
887 + 'options' => [
888 + '' => esc_html__('Default', 'uicore-elements'),
889 + '100' => '100%',
890 + '80' => '80%',
891 + '75' => '75%',
892 + '70' => '70%',
893 + '66' => '66%',
894 + '60' => '60%',
895 + '50' => '50%',
896 + '40' => '40%',
897 + '33' => '33%',
898 + '30' => '30%',
899 + '25' => '25%',
900 + '20' => '20%',
901 + ],
902 + 'default' => '100',
903 + ]
904 + );
905 + $this->add_responsive_control(
906 + 'button_align',
907 + [
908 + 'label' => esc_html__('Alignment', 'uicore-elements'),
909 + 'type' => Controls_Manager::CHOOSE,
910 + 'options' => [
911 + 'left' => [
912 + 'title' => esc_html__('Left', 'uicore-elements'),
913 + 'icon' => 'eicon-text-align-left',
1043 914 ],
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 - ],
915 + 'center' => [
916 + 'title' => esc_html__('Center', 'uicore-elements'),
917 + 'icon' => 'eicon-text-align-center',
1069 918 ],
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,
919 + 'right' => [
920 + 'title' => esc_html__('Right', 'uicore-elements'),
921 + 'icon' => 'eicon-text-align-right',
1083 922 ],
1084 - 'ai' => [
1085 - 'active' => false,
923 + 'stretch' => [
924 + 'title' => esc_html__('Justified', 'uicore-elements'),
925 + 'icon' => 'eicon-text-align-justify',
1086 926 ],
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' ),
927 + ],
928 + 'default' => 'stretch',
929 + 'prefix_class' => 'ui-e-submit-align-%s-',
930 + ]
931 + );
932 + $this->add_control(
933 + 'button_text',
934 + [
935 + 'label' => esc_html__('Submit', 'uicore-elements'),
936 + 'type' => Controls_Manager::TEXT,
937 + 'default' => esc_html__('Send', 'uicore-elements'),
938 + 'placeholder' => esc_html__('Send', 'uicore-elements'),
939 + 'dynamic' => [
940 + 'active' => true,
941 + ],
942 + 'ai' => [
943 + 'active' => false,
944 + ],
945 + ]
946 + );
947 + $this->add_control(
948 + 'selected_button_icon',
949 + [
950 + 'label' => esc_html__('Icon', 'uicore-elements'),
951 + 'type' => Controls_Manager::ICONS,
952 + 'skin' => 'inline',
953 + 'label_block' => false,
954 + ]
955 + );
956 + $this->add_control(
957 + 'button_icon_align',
958 + [
959 + 'label' => esc_html__('Icon Position', 'uicore-elements'),
960 + 'type' => Controls_Manager::SELECT,
961 + 'default' => 'left',
962 + 'options' => [
963 + 'left' => esc_html__('Before', 'uicore-elements'),
964 + 'right' => esc_html__('After', 'uicore-elements'),
965 + ],
966 + 'condition' => [
967 + 'selected_button_icon[value]!' => '',
968 + ],
969 + ]
970 + );
971 + $this->add_control(
972 + 'button_icon_indent',
973 + [
974 + 'label' => esc_html__('Icon Spacing', 'uicore-elements'),
975 + 'type' => Controls_Manager::SLIDER,
976 + 'size_units' => ['px', 'em', 'rem', 'custom'],
977 + 'range' => [
978 + 'px' => [
979 + 'max' => 100,
1107 980 ],
1108 - 'condition' => [
1109 - 'selected_button_icon[value]!' => '',
981 + 'em' => [
982 + 'max' => 10,
1110 983 ],
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 - ],
984 + 'rem' => [
985 + 'max' => 10,
1129 986 ],
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',
987 + ],
988 + 'condition' => [
989 + 'selected_button_icon[value]!' => '',
990 + ],
991 + 'selectors' => [
992 + '{{WRAPPER}} .elementor-button .ui-e-align-right' => 'margin-left: {{SIZE}}{{UNIT}};',
993 + '{{WRAPPER}} .elementor-button .ui-e-align-left' => 'margin-right: {{SIZE}}{{UNIT}};',
994 + ],
995 + ]
996 + );
997 + $this->add_control(
998 + 'button_css_id',
1162 999 [
1163 - 'label' => esc_html__( 'Actions After Submit', 'uicore-elements' ),
1000 + 'label' => esc_html__('Button ID', 'uicore-elements'),
1001 + 'type' => Controls_Manager::TEXT,
1002 + 'default' => '',
1003 + 'ai' => [
1004 + 'active' => false,
1005 + ],
1006 + 'title' => esc_html__('Add your custom id WITHOUT the Pound key. e.g: my-id', 'uicore-elements'),
1007 + 'description' => esc_html__('Please make sure the ID is unique and not used elsewhere on the page this form is displayed. This field allows `A-z 0-9` & underscore chars without spaces.', 'uicore-elements'),
1008 + 'separator' => 'before',
1009 + 'dynamic' => [
1010 + 'active' => true,
1011 + ],
1164 1012 ]
1165 1013 );
1166 1014
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 1015
1183 1016 $this->end_controls_section();
1184 1017
1018 + $this->TRAIT_register_submit_actions_controls(Contact_Form_Service::get_form_submit_options());
1019 +
1185 1020 // Submit sections
1186 1021 $this->start_controls_section(
1187 1022 'section_email',
1188 1023 [
1189 - 'label' => esc_html__( 'Email', 'uicore-elements' ),
1024 + 'label' => esc_html__('Email', 'uicore-elements'),
1190 1025 'condition' => [
1191 1026 'submit_actions' => 'email',
1192 1027 ],
1193 1028 ]
@@ -1192,9 +1027,9 @@
1192 1027 ],
1193 1028 ]
1194 1029 );
1195 1030
1196 - $this->register_submit_email_controls($this);
1031 + $this->TRAIT_register_submit_email_controls($this);
1197 1032
1198 1033 $this->end_controls_section();
1199 1034
1200 1035 $this->start_controls_section(
@@ -1199,9 +1034,9 @@
1199 1034
1200 1035 $this->start_controls_section(
1201 1036 'section_email_2',
1202 1037 [
1203 - 'label' => esc_html__( 'Email 2', 'uicore-elements' ),
1038 + 'label' => esc_html__('Email 2', 'uicore-elements'),
1204 1039 'condition' => [
1205 1040 'submit_actions' => 'email_2',
1206 1041 ],
1207 1042 ]
@@ -1206,937 +1041,291 @@
1206 1041 ],
1207 1042 ]
1208 1043 );
1209 1044
1210 - $this->register_submit_email_controls($this, '_2');
1045 + $this->TRAIT_register_submit_email_controls($this, '_2');
1211 1046
1212 1047 $this->end_controls_section();
1213 1048
1214 - $this->start_controls_section(
1215 - 'section_redirect',
1049 + $this->TRAIT_register_submit_redirect_controls();
1050 + $this->TRAIT_register_submit_popup_controls($this);
1051 + $this->TRAIT_register_submit_webhook_controls();
1052 + $this->TRAIT_register_submit_newsletter_services_controls(Newsletter_Services::get_services_list('keys'), true);
1053 + $default_messages = Contact_Form_Service::get_default_messages();
1054 + $this->TRAIT_register_additional_controls($default_messages);
1055 +
1056 + $this->TRAIT_register_all_form_style_controls();
1057 +
1058 + // Custom Fields additional Controls injection
1059 + $this->start_injection([
1060 + 'of' => 'redirect_message',
1061 + 'at' => 'before',
1062 + ]);
1063 + $this->add_control(
1064 + 'required_fields_message',
1216 1065 [
1217 - 'label' => esc_html__( 'Redirect', 'uicore-elements' ),
1218 - 'condition' => [
1219 - 'submit_actions' => 'redirect',
1066 + 'label' => esc_html__('Required Fields', 'uicore-elements'),
1067 + 'type' => Controls_Manager::TEXT,
1068 + 'default' => $default_messages['required'],
1069 + 'placeholder' => $default_messages['required'],
1070 + 'label_block' => true,
1071 + 'conditions' => [
1072 + 'terms' => [
1073 + [
1074 + 'name' => 'custom_messages',
1075 + 'operator' => '!=',
1076 + 'value' => '',
1077 + ],
1078 + ],
1220 1079 ],
1080 + 'render_type' => 'none',
1081 + 'dynamic' => [
1082 + 'active' => true,
1083 + ],
1221 1084 ]
1222 1085 );
1086 + $this->end_injection();
1223 1087
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 - );
1088 + // Specific Form style controls
1089 + $this->start_injection([
1090 + 'of' => 'form_styles_component_divider',
1091 + 'at' => 'after',
1092 + ]);
1243 1093
1244 - $this->end_controls_section();
1245 -
1246 - $default_messages = Contact_Form_Service::get_default_messages();
1247 - $this->start_controls_section(
1248 - 'section_form_options',
1094 + $this->add_control(
1095 + 'heading_html',
1249 1096 [
1250 - 'label' => esc_html__( 'Additional Options', 'uicore-elements' ),
1251 - 'tab' => Controls_Manager::TAB_CONTENT,
1097 + 'label' => esc_html__('HTML Field', 'uicore-elements'),
1098 + 'type' => Controls_Manager::HEADING,
1252 1099 ]
1253 1100 );
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,
1101 + $this->add_control(
1102 + 'html_spacing',
1103 + [
1104 + 'label' => esc_html__('Spacing', 'uicore-elements'),
1105 + 'type' => Controls_Manager::SLIDER,
1106 + 'size_units' => ['px', 'em', 'rem', 'custom'],
1107 + 'default' => [
1108 + 'size' => 0,
1109 + ],
1110 + 'range' => [
1111 + 'px' => [
1112 + 'max' => 60,
1262 1113 ],
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,
1114 + 'em' => [
1115 + 'max' => 6,
1268 1116 ],
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' ),
1117 + 'rem' => [
1118 + 'max' => 6,
1279 1119 ],
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 - );
1120 + ],
1121 + 'selectors' => [
1122 + '{{WRAPPER}} .ui-e-field-type-html' => 'padding-bottom: {{SIZE}}{{UNIT}};',
1123 + ],
1124 + ]
1125 + );
1126 + $this->add_control(
1127 + 'html_color',
1128 + [
1129 + 'label' => esc_html__('Color', 'uicore-elements'),
1130 + 'type' => Controls_Manager::COLOR,
1131 + 'selectors' => [
1132 + '{{WRAPPER}} .ui-e-field-type-html' => 'color: {{VALUE}};',
1133 + ],
1134 + ]
1135 + );
1136 + $this->add_group_control(
1137 + Group_Control_Typography::get_type(),
1138 + [
1139 + 'name' => 'html_typography',
1140 + 'selector' => '{{WRAPPER}} .ui-e-field-type-html',
1141 + 'global' => [
1142 + 'default' => Global_Typography::TYPOGRAPHY_TEXT,
1143 + ],
1144 + ]
1145 + );
1355 1146
1356 - $this->end_controls_section();
1147 + $this->add_control(
1148 + 'heading_file',
1149 + [
1150 + 'label' => esc_html__('Upload File Field', 'uicore-elements'),
1151 + 'type' => Controls_Manager::HEADING,
1152 + 'separator' => 'before',
1153 + ]
1154 + );
1155 + $this->add_control(
1156 + 'file_color',
1157 + [
1158 + 'label' => esc_html__('Color', 'uicore-elements'),
1159 + 'type' => Controls_Manager::COLOR,
1160 + 'selectors' => [
1161 + '{{WRAPPER}} .ui-e-field-type-file input.ui-e-field' => 'color: {{VALUE}};',
1162 + ],
1163 + 'default' => 'var(--e-global-color-uicore_body)',
1357 1164
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 - }
1165 + ]
1166 + );
1167 + $this->end_injection();
1168 + }
1995 1169 function recaptcha_js()
1996 1170 {
1997 - ?>
1171 + ?>
1998 1172 <script>
1999 - window.uicore_elements_recaptcha = '<?php echo get_option('uicore_elements_recaptcha_site_key'); ?>';
1173 + window.uicore_elements_recaptcha = '<?php echo esc_html(get_option('uicore_elements_recaptcha_site_key')); ?>';
2000 1174 </script>
2001 - <?php
1175 + <?php
2002 1176 }
2003 1177
2004 - protected function render() {
1178 + protected function render()
1179 + {
2005 1180
2006 - $instance = $this->get_settings_for_display();
1181 + $instance = $this->get_settings_for_display();
2007 1182 $is_recaptcha_required = false;
2008 1183
1184 + // Save widget settings so form API can retrieve them
1185 + set_transient('ui_e_form_widget_settings_' . $this->get_id(), $instance, DAY_IN_SECONDS);
1186 +
2009 1187 // 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 - );
1188 + $this->add_render_attribute(
1189 + [
1190 + 'wrapper' => [
1191 + 'class' => [
1192 + 'ui-e-fields-wrp',
1193 + ],
1194 + ],
1195 + 'submit-group' => [
1196 + 'class' => [
1197 + 'ui-e-field-group',
1198 + 'elementor-column',
1199 + 'ui-e-field-type-submit',
1200 + ],
1201 + ],
1202 + 'button' => [
1203 + 'class' => 'elementor-button',
1204 + ],
1205 + 'icon-align' => [
1206 + 'class' => [
1207 + empty($instance['button_icon_align']) ? '' : 'ui-e-icon ui-e-align-' . $instance['button_icon_align'],
1208 + ],
1209 + ],
1210 + ]
1211 + );
2034 1212
2035 1213 // Fallback for empty control values
2036 - if ( empty( $instance['button_width'] ) ) {
2037 - $instance['button_width'] = '100';
2038 - }
1214 + if (empty($instance['button_width'])) {
1215 + $instance['button_width'] = '100';
1216 + }
2039 1217
2040 - // Button atts
2041 - $this->add_render_attribute( 'submit-group', 'class', 'elementor-col-' . $instance['button_width'] . ' e-form__buttons' );
1218 + // Button atts
1219 + $this->add_render_attribute('submit-group', 'class', 'elementor-col-' . $instance['button_width'] . ' e-form__buttons');
2042 1220
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 - }
1221 + if (! empty($instance['button_width_tablet'])) {
1222 + $this->add_render_attribute('submit-group', 'class', 'elementor-md-' . $instance['button_width_tablet']);
1223 + }
1224 + if (! empty($instance['button_width_mobile'])) {
1225 + $this->add_render_attribute('submit-group', 'class', 'elementor-sm-' . $instance['button_width_mobile']);
1226 + }
1227 + if ($instance['button_hover_animation']) {
1228 + $this->add_render_attribute('button', 'class', 'elementor-animation-' . $instance['button_hover_animation']);
1229 + }
2052 1230
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 - }
1231 + // Form atts
1232 + if (! empty($instance['form_id'])) {
1233 + $this->add_render_attribute('form', 'id', $instance['form_id']);
1234 + }
1235 + if (! empty($instance['form_name'])) {
1236 + $this->add_render_attribute('form', 'name', $instance['form_name']);
1237 + }
1238 + if ('no' === $instance['form_validation']) {
1239 + $this->add_render_attribute('form', 'novalidate');
1240 + }
1241 + if (! empty($instance['button_css_id'])) {
1242 + $this->add_render_attribute('button', 'id', $instance['button_css_id']);
1243 + }
2066 1244
2067 - $referer_title = trim( wp_title( '', false ) );
2068 - if ( ! $referer_title && is_home() ) {
2069 - $referer_title = get_option( 'blogname' );
2070 - }
1245 + $referer_title = trim(wp_title('', false));
1246 + if (! $referer_title && is_home()) {
1247 + $referer_title = get_option('blogname');
1248 + }
2071 1249
2072 - ?>
1250 + // Get default messages
1251 + $messages = Contact_Form_Service::get_default_messages();
2073 1252
2074 - <form class="ui-e-form" method="post" <?php $this->print_render_attribute_string( 'form' ); ?>>
1253 + // Set frontend validation message
1254 + $front_msg_required = isset($instance['required_fields_message'])
1255 + ? $instance['required_fields_message']
1256 + : $messages['required'];
1257 + ?>
2075 1258
2076 - <input type="hidden" name="post_id" value="<?php echo esc_attr( get_the_ID()); ?>"/>
1259 + <form class="ui-e-form" method="post" <?php $this->print_render_attribute_string('form'); ?>>
2077 1260
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 );
1261 + <input type="hidden" name="post_id" value="<?php echo esc_attr(get_the_ID()); ?>" />
1262 + <input type="hidden" name="widget_type" value="contact-form">
2082 1263
2083 - $field_type = $item['field_type'];
1264 + <input type="hidden" name="required_fields_message" value="<?php echo esc_html($front_msg_required); ?>">
2084 1265
2085 - if( $field_type === 'recaptcha' || $field_type === 'recaptcha_v3' ){
1266 + <div <?php $this->print_render_attribute_string('wrapper'); ?>>
1267 +
1268 + <?php foreach ($instance['form_fields'] as $item_index => $item) :
1269 + $this->form_fields_render_attributes($item_index, $instance, $item);
1270 +
1271 + $field_type = $item['field_type'];
1272 +
1273 + if ($field_type === 'recaptcha' || $field_type === 'recaptcha_v3') {
2086 1274 $is_recaptcha_required = true;
2087 1275 }
2088 1276
2089 - $print_label = ! in_array( $item['field_type'], [ 'hidden', 'html' ], true );
2090 - ?>
1277 + $print_label = ! in_array($item['field_type'], ['hidden', 'html'], true);
1278 + ?>
2091 1279
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>
1280 + <div <?php $this->print_render_attribute_string('field-group' . $item_index); ?>>
1281 + <?php
1282 + // Print label (excepts if recaptcha)
1283 + if ($print_label && $item['field_label'] && $item['field_type'] !== 'recaptcha' && $item['field_type'] !== 'recaptcha_v3') {
1284 + ?>
1285 + <label <?php $this->print_render_attribute_string('label' . $item_index); ?>>
1286 + <?php // PHPCS - the variable $item['field_label'] is safe.
1287 + echo Helper::esc_string($item['field_label']); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1288 + ?>
1289 + </label>
2101 1290 <?php
2102 1291 }
2103 1292
2104 - // Print field
2105 - switch ( $item['field_type'] ) :
2106 - case 'html':
2107 - echo do_shortcode( $item['field_html'] );
2108 - break;
1293 + // Print field
1294 + switch ($item['field_type']):
1295 + case 'html':
1296 + echo wp_kses_post(do_shortcode($item['field_html']));
1297 + break;
2109 1298
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;
1299 + case 'textarea':
1300 + // PHPCS - the method build_textarea_field is safe.
1301 + echo $this->build_textarea_field($item, $item_index); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1302 + break;
2114 1303
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;
1304 + case 'select':
1305 + // PHPCS - the method build_select_field is safe.
1306 + echo $this->build_select_field($item, $item_index); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1307 + break;
2119 1308
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;
1309 + case 'acceptance':
1310 + // PHPCS - the method build_select_field is safe.
1311 + $this->build_acceptance_field($item, $item_index); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1312 + break;
2124 1313
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;
1314 + case 'radio':
1315 + case 'checkbox':
1316 + // PHPCS - the method build_radio_checkbox_field is safe.
1317 + echo $this->build_radio_checkbox_field($item, $item_index, $item['field_type']); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1318 + break;
2130 1319
2131 1320 case 'address': // is actually honeypot
2132 1321 // PHPCS - the method build_honeypot_field is safe.
2133 - echo $this->build_honeypot_field( $item, $item_index ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1322 + echo $this->build_honeypot_field($item, $item_index); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2134 1323 break;
2135 1324
2136 1325 case 'recaptcha':
2137 1326 // get widget ID
2138 - echo '<input type="hidden" name="recaptcha"/> <div id="ui-e-recaptcha-'.esc_attr($this->get_ID()).'"></div>';
1327 + echo '<input type="hidden" name="recaptcha"/> <div id="ui-e-recaptcha-' . esc_attr($this->get_ID()) . '"></div>';
2139 1328 break;
2140 1329
2141 1330 case 'recaptcha_v3':
2142 1331 echo '<input type="hidden" name="recaptcha_v3"/>';
@@ -2141,283 +1330,71 @@
2141 1330 case 'recaptcha_v3':
2142 1331 echo '<input type="hidden" name="recaptcha_v3"/>';
2143 1332 break;
2144 1333
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;
1334 + // All other cases are covered by the add_render_atribute()
1335 + default:
1336 + $this->add_render_attribute('input' . $item_index, 'class', 'ui-e-field-textual');
1337 + ?>
1338 + <input size="1" <?php $this->print_render_attribute_string('input' . $item_index); ?>>
1339 + <?php
1340 + break;
2152 1341
2153 - endswitch;
2154 - ?>
2155 - </div>
1342 + endswitch;
1343 + ?>
1344 + </div>
2156 1345
2157 - <?php endforeach; ?>
1346 + <?php endforeach; ?>
2158 1347
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>
1348 + <div <?php $this->print_render_attribute_string('submit-group'); ?>>
1349 + <button type="submit" <?php $this->print_render_attribute_string('button'); ?>>
1350 + <span <?php $this->print_render_attribute_string('content-wrapper'); ?>>
1351 + <?php if (! empty($instance['button_icon']) || ! empty($instance['selected_button_icon'])) : ?>
1352 + <span <?php $this->print_render_attribute_string('icon-align'); ?>>
1353 + <?php Icons_Manager::render_icon($instance['selected_button_icon'], ['aria-hidden' => 'true']); ?>
1354 + <?php if (empty($instance['button_text'])) : ?>
1355 + <span class="elementor-screen-only"><?php echo esc_html__('Submit', 'uicore-elements'); ?></span>
1356 + <?php endif; ?>
1357 + </span>
1358 + <?php endif; ?>
1359 + <?php if (! empty($instance['button_text'])) : ?>
1360 + <span class="ui-e-text"><?php $this->print_unescaped_setting('button_text'); ?></span>
1361 + <?php endif; ?>
1362 + </span>
1363 + </button>
1364 + </div>
2176 1365
2177 - </div>
1366 + </div>
2178 1367
2179 1368 <div class="ui-e-message <?php echo $this->is_edit_mode() ? 'elementor-hidden' : ''; ?>">
2180 - <?php if($this->is_edit_mode()) :
1369 + <?php if ($this->is_edit_mode()) :
2181 1370 // 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; ?>
1371 + $success = isset($instance['success_message'])
1372 + ? $instance['success_message']
1373 + : $messages['success'];
1374 + $error = isset($instance['error_message'])
1375 + ? $instance['error_message']
1376 + : $messages['error'];
1377 + ?>
1378 + <span class="success"> <?php echo esc_html($success); ?> </span> <br>
1379 + <span class="error"> <?php echo esc_html($error); ?> </span>
1380 + <?php endif; ?>
2189 1381 </div>
2190 - </form>
2191 - <?php
1382 + </form>
1383 + <?php
2192 1384
2193 1385 //add js to footer if recaptcha is enabled
2194 - if($is_recaptcha_required){
1386 + if ($is_recaptcha_required) {
2195 1387 add_action('wp_footer', [$this, 'recaptcha_js'], 999);
2196 1388 }
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 1389
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 - }
1390 + // Add frontend validation messages to js var
1391 + ?>
1392 + <script>
1393 + window.ui_e_form_validation_messages = <?php echo json_encode([
1394 + 'required_fields' => esc_html($front_msg_required),
1395 + ]); ?>;
1396 + </script>
1397 +<?php
1398 + }
2422 1399 }
2423 -\Elementor\Plugin::instance()->widgets_manager->register(new ContactForm());
1400 +\Elementor\Plugin::instance()->widgets_manager->register(new ContactForm());