PluginProbe
NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar / 3.2.8
NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar v3.2.8
3.3.1 3.3.0 3.2.14 3.2.13 3.2.12 3.2.11 3.2.10 3.2.9 3.2.8 3.2.7 trunk 0.2.5.5 0.2.5.6 0.2.5.7 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.2.0 1.2.1 All 156 releases
notificationx / includes / Extensions / Elementor / FormWidget.php

FormWidget.php in NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar 3.2.8, at includes/Extensions/Elementor/FormWidget.php

636 lines 27.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * NotificationX Elementor Form Widget
4 *
5 * A simple Name / Email / Message form whose submissions are saved into
6 * the NotificationX `nx_entries` table via the existing
7 * `notificationx/v1/popup-submit` REST endpoint. The widget must be bound
8 * to an existing NotificationX campaign of source `popup_notification`
9 * or `exit_intent_custom`.
10 *
11 * @package NotificationX\Extensions\Elementor
12 */
13
14 namespace NotificationX\Extensions\Elementor;
15
16 use Elementor\Controls_Manager;
17 use Elementor\Group_Control_Border;
18 use Elementor\Group_Control_Box_Shadow;
19 use Elementor\Group_Control_Typography;
20 use Elementor\Widget_Base;
21 use NotificationX\Core\PostType;
22
23 if ( ! defined( 'ABSPATH' ) ) {
24 exit;
25 }
26
27 /**
28 * Column-width options shared across all field controls.
29 * Keys are the CSS percentage values rendered into `flex-basis`.
30 */
31 if ( ! function_exists( __NAMESPACE__ . '\\nx_form_widths' ) ) {
32 function nx_form_widths() {
33 return [
34 '100' => '100%',
35 '75' => '75%',
36 '66' => '66%',
37 '50' => '50%',
38 '33' => '33%',
39 '25' => '25%',
40 ];
41 }
42 }
43
44 class FormWidget extends Widget_Base {
45
46 public function get_name() {
47 return 'nx-form';
48 }
49
50 public function get_title() {
51 return esc_html__( 'NotificationX Form', 'notificationx' );
52 }
53
54 public function get_icon() {
55 return 'eicon-form-horizontal';
56 }
57
58 public function get_categories() {
59 return [ 'notificationx' ];
60 }
61
62 public function get_keywords() {
63 return [ 'form', 'contact', 'lead', 'notificationx', 'nx', 'entries', 'subscribe' ];
64 }
65
66 public function get_script_depends() {
67 return [ 'nx-elementor-form' ];
68 }
69
70 public function get_style_depends() {
71 return [ 'nx-elementor-form' ];
72 }
73
74 /**
75 * Existing NX Popup / Exit-Intent campaigns to bind submissions to.
76 *
77 * @return array<int|string,string>
78 */
79 private function get_nx_campaigns() {
80 $options = [ '' => esc_html__( '— Select a Campaign —', 'notificationx' ) ];
81
82 if ( ! class_exists( PostType::class ) ) {
83 return $options;
84 }
85
86 $posts = PostType::get_instance()->get_posts(
87 [], // can't AND two source values via a simple where; filter below.
88 'nx_id, title, source'
89 );
90
91 if ( is_array( $posts ) ) {
92 foreach ( $posts as $post ) {
93 if ( empty( $post['source'] ) ) {
94 continue;
95 }
96 if ( ! in_array( $post['source'], [ 'popup_notification', 'exit_intent_custom' ], true ) ) {
97 continue;
98 }
99 $label = $post['title'] ?: sprintf( __( '#%d', 'notificationx' ), $post['nx_id'] );
100 $options[ (string) $post['nx_id'] ] = sprintf(
101 '%s (%s)',
102 $label,
103 $post['source'] === 'exit_intent_custom' ? __( 'Exit Intent', 'notificationx' ) : __( 'Popup', 'notificationx' )
104 );
105 }
106 }
107
108 return $options;
109 }
110
111 protected function register_controls() {
112
113 // ── Form Settings ─────────────────────────────────────────────────
114 $this->start_controls_section(
115 'section_form_settings',
116 [ 'label' => esc_html__( 'Form Settings', 'notificationx' ) ]
117 );
118
119 $this->add_control(
120 'nx_campaign_id',
121 [
122 'label' => esc_html__( 'Select Notification ID', 'notificationx' ),
123 'type' => Controls_Manager::SELECT,
124 'options' => $this->get_nx_campaigns(),
125 'default' => '',
126 'description' => esc_html__( 'Submissions are saved as entries against the selected Popup or Exit-Intent campaign.', 'notificationx' ),
127 ]
128 );
129
130 $this->add_control(
131 'nx_form_title',
132 [
133 'label' => esc_html__( 'Form Title', 'notificationx' ),
134 'type' => Controls_Manager::TEXT,
135 'default' => esc_html__( 'Get in touch', 'notificationx' ),
136 'dynamic' => [ 'active' => true ],
137 ]
138 );
139
140 // Name field
141 $this->add_control(
142 'nx_name_heading',
143 [ 'label' => esc_html__( 'Name Field', 'notificationx' ), 'type' => Controls_Manager::HEADING, 'separator' => 'before' ]
144 );
145 $this->add_control(
146 'nx_show_name',
147 [ 'label' => esc_html__( 'Show Name', 'notificationx' ), 'type' => Controls_Manager::SWITCHER, 'return_value' => 'yes', 'default' => 'yes' ]
148 );
149 $this->add_responsive_control(
150 'nx_name_width',
151 [
152 'label' => esc_html__( 'Column Width', 'notificationx' ),
153 'type' => Controls_Manager::SELECT,
154 'options' => nx_form_widths(),
155 'default' => '100',
156 'condition' => [ 'nx_show_name' => 'yes' ],
157 ]
158 );
159 $this->add_control(
160 'nx_name_label',
161 [ 'label' => esc_html__( 'Label', 'notificationx' ), 'type' => Controls_Manager::TEXT, 'default' => esc_html__( 'Name', 'notificationx' ), 'condition' => [ 'nx_show_name' => 'yes' ] ]
162 );
163 $this->add_control(
164 'nx_name_placeholder',
165 [ 'label' => esc_html__( 'Placeholder', 'notificationx' ), 'type' => Controls_Manager::TEXT, 'default' => esc_html__( 'Your name', 'notificationx' ), 'condition' => [ 'nx_show_name' => 'yes' ] ]
166 );
167 $this->add_control(
168 'nx_name_required',
169 [ 'label' => esc_html__( 'Required', 'notificationx' ), 'type' => Controls_Manager::SWITCHER, 'return_value' => 'yes', 'default' => '', 'condition' => [ 'nx_show_name' => 'yes' ] ]
170 );
171
172 // Email field
173 $this->add_control(
174 'nx_email_heading',
175 [ 'label' => esc_html__( 'Email Field', 'notificationx' ), 'type' => Controls_Manager::HEADING, 'separator' => 'before' ]
176 );
177 $this->add_control(
178 'nx_show_email',
179 [ 'label' => esc_html__( 'Show Email', 'notificationx' ), 'type' => Controls_Manager::SWITCHER, 'return_value' => 'yes', 'default' => 'yes' ]
180 );
181 $this->add_responsive_control(
182 'nx_email_width',
183 [
184 'label' => esc_html__( 'Column Width', 'notificationx' ),
185 'type' => Controls_Manager::SELECT,
186 'options' => nx_form_widths(),
187 'default' => '100',
188 'condition' => [ 'nx_show_email' => 'yes' ],
189 ]
190 );
191 $this->add_control(
192 'nx_email_label',
193 [ 'label' => esc_html__( 'Label', 'notificationx' ), 'type' => Controls_Manager::TEXT, 'default' => esc_html__( 'Email', 'notificationx' ), 'condition' => [ 'nx_show_email' => 'yes' ] ]
194 );
195 $this->add_control(
196 'nx_email_placeholder',
197 [ 'label' => esc_html__( 'Placeholder', 'notificationx' ), 'type' => Controls_Manager::TEXT, 'default' => esc_html__( 'you@example.com', 'notificationx' ), 'condition' => [ 'nx_show_email' => 'yes' ] ]
198 );
199 $this->add_control(
200 'nx_email_required',
201 [ 'label' => esc_html__( 'Required', 'notificationx' ), 'type' => Controls_Manager::SWITCHER, 'return_value' => 'yes', 'default' => 'yes', 'condition' => [ 'nx_show_email' => 'yes' ] ]
202 );
203
204 // Message field
205 $this->add_control(
206 'nx_message_heading',
207 [ 'label' => esc_html__( 'Message Field', 'notificationx' ), 'type' => Controls_Manager::HEADING, 'separator' => 'before' ]
208 );
209 $this->add_control(
210 'nx_show_message',
211 [ 'label' => esc_html__( 'Show Message', 'notificationx' ), 'type' => Controls_Manager::SWITCHER, 'return_value' => 'yes', 'default' => 'yes' ]
212 );
213 $this->add_responsive_control(
214 'nx_message_width',
215 [
216 'label' => esc_html__( 'Column Width', 'notificationx' ),
217 'type' => Controls_Manager::SELECT,
218 'options' => nx_form_widths(),
219 'default' => '100',
220 'condition' => [ 'nx_show_message' => 'yes' ],
221 ]
222 );
223 $this->add_control(
224 'nx_message_label',
225 [ 'label' => esc_html__( 'Label', 'notificationx' ), 'type' => Controls_Manager::TEXT, 'default' => esc_html__( 'Message', 'notificationx' ), 'condition' => [ 'nx_show_message' => 'yes' ] ]
226 );
227 $this->add_control(
228 'nx_message_placeholder',
229 [ 'label' => esc_html__( 'Placeholder', 'notificationx' ), 'type' => Controls_Manager::TEXT, 'default' => esc_html__( 'Write your message…', 'notificationx' ), 'condition' => [ 'nx_show_message' => 'yes' ] ]
230 );
231 $this->add_control(
232 'nx_message_rows',
233 [ 'label' => esc_html__( 'Rows', 'notificationx' ), 'type' => Controls_Manager::NUMBER, 'default' => 4, 'min' => 1, 'max' => 20, 'condition' => [ 'nx_show_message' => 'yes' ] ]
234 );
235 $this->add_control(
236 'nx_message_required',
237 [ 'label' => esc_html__( 'Required', 'notificationx' ), 'type' => Controls_Manager::SWITCHER, 'return_value' => 'yes', 'default' => '', 'condition' => [ 'nx_show_message' => 'yes' ] ]
238 );
239
240 // Submit
241 $this->add_control(
242 'nx_submit_heading',
243 [ 'label' => esc_html__( 'Submit', 'notificationx' ), 'type' => Controls_Manager::HEADING, 'separator' => 'before' ]
244 );
245 $this->add_responsive_control(
246 'nx_submit_width',
247 [
248 'label' => esc_html__( 'Column Width', 'notificationx' ),
249 'type' => Controls_Manager::SELECT,
250 'options' => nx_form_widths(),
251 'default' => '100',
252 ]
253 );
254 $this->add_control(
255 'nx_submit_text',
256 [ 'label' => esc_html__( 'Button Text', 'notificationx' ), 'type' => Controls_Manager::TEXT, 'default' => esc_html__( 'Submit', 'notificationx' ) ]
257 );
258 $this->add_control(
259 'nx_success_message',
260 [ 'label' => esc_html__( 'Success Message', 'notificationx' ), 'type' => Controls_Manager::TEXTAREA, 'default' => esc_html__( 'Thanks! Your submission has been received.', 'notificationx' ) ]
261 );
262 $this->add_control(
263 'nx_error_message',
264 [ 'label' => esc_html__( 'Error Message', 'notificationx' ), 'type' => Controls_Manager::TEXTAREA, 'default' => esc_html__( 'Something went wrong. Please try again.', 'notificationx' ) ]
265 );
266
267 $this->end_controls_section();
268
269 // ── Style: Form ──────────────────────────────────────────────────
270 $this->start_controls_section(
271 'section_style_form',
272 [ 'label' => esc_html__( 'Form', 'notificationx' ), 'tab' => Controls_Manager::TAB_STYLE ]
273 );
274
275 $this->add_responsive_control(
276 'nx_form_align',
277 [
278 'label' => esc_html__( 'Alignment', 'notificationx' ),
279 'type' => Controls_Manager::CHOOSE,
280 'options' => [
281 'left' => [ 'title' => esc_html__( 'Left', 'notificationx' ), 'icon' => 'eicon-text-align-left' ],
282 'center' => [ 'title' => esc_html__( 'Center', 'notificationx' ), 'icon' => 'eicon-text-align-center' ],
283 'right' => [ 'title' => esc_html__( 'Right', 'notificationx' ), 'icon' => 'eicon-text-align-right' ],
284 ],
285 'default' => 'left',
286 'selectors' => [ '{{WRAPPER}} .nx-form-title' => 'text-align: {{VALUE}};' ],
287 ]
288 );
289
290 $this->add_group_control(
291 Group_Control_Typography::get_type(),
292 [ 'name' => 'nx_title_typography', 'selector' => '{{WRAPPER}} .nx-form-title' ]
293 );
294
295 $this->add_control(
296 'nx_title_color',
297 [
298 'label' => esc_html__( 'Title Color', 'notificationx' ),
299 'type' => Controls_Manager::COLOR,
300 'selectors' => [ '{{WRAPPER}} .nx-form-title' => 'color: {{VALUE}};' ],
301 ]
302 );
303
304 $this->end_controls_section();
305
306 // ── Style: Fields ────────────────────────────────────────────────
307 $this->start_controls_section(
308 'section_style_fields',
309 [ 'label' => esc_html__( 'Fields', 'notificationx' ), 'tab' => Controls_Manager::TAB_STYLE ]
310 );
311
312 $this->add_control(
313 'nx_label_color',
314 [
315 'label' => esc_html__( 'Label Color', 'notificationx' ),
316 'type' => Controls_Manager::COLOR,
317 'selectors' => [ '{{WRAPPER}} .nx-form-label' => 'color: {{VALUE}};' ],
318 ]
319 );
320
321 $this->add_group_control(
322 Group_Control_Typography::get_type(),
323 [ 'name' => 'nx_label_typography', 'selector' => '{{WRAPPER}} .nx-form-label' ]
324 );
325
326 $this->add_control(
327 'nx_input_text_color',
328 [
329 'label' => esc_html__( 'Input Text Color', 'notificationx' ),
330 'type' => Controls_Manager::COLOR,
331 'selectors' => [ '{{WRAPPER}} .nx-form-input' => 'color: {{VALUE}};' ],
332 ]
333 );
334
335 $this->add_control(
336 'nx_input_bg_color',
337 [
338 'label' => esc_html__( 'Input Background', 'notificationx' ),
339 'type' => Controls_Manager::COLOR,
340 'selectors' => [ '{{WRAPPER}} .nx-form-input' => 'background-color: {{VALUE}};' ],
341 ]
342 );
343
344 $this->add_control(
345 'nx_placeholder_color',
346 [
347 'label' => esc_html__( 'Placeholder Color', 'notificationx' ),
348 'type' => Controls_Manager::COLOR,
349 'selectors' => [
350 '{{WRAPPER}} .nx-form-input::-webkit-input-placeholder' => 'color: {{VALUE}};',
351 '{{WRAPPER}} .nx-form-input::-moz-placeholder' => 'color: {{VALUE}};',
352 '{{WRAPPER}} .nx-form-input:-ms-input-placeholder' => 'color: {{VALUE}};',
353 '{{WRAPPER}} .nx-form-input::placeholder' => 'color: {{VALUE}};',
354 ],
355 ]
356 );
357
358 $this->add_group_control(
359 Group_Control_Typography::get_type(),
360 [
361 'name' => 'nx_placeholder_typography',
362 'label' => esc_html__( 'Placeholder Typography', 'notificationx' ),
363 'selector' => '{{WRAPPER}} .nx-form-input::placeholder',
364 ]
365 );
366
367 $this->add_group_control(
368 Group_Control_Border::get_type(),
369 [
370 'name' => 'nx_input_border',
371 'selector' => '{{WRAPPER}} .nx-form-input',
372 ]
373 );
374
375 $this->add_control(
376 'nx_input_radius',
377 [
378 'label' => esc_html__( 'Border Radius', 'notificationx' ),
379 'type' => Controls_Manager::DIMENSIONS,
380 'size_units' => [ 'px', '%' ],
381 'selectors' => [ '{{WRAPPER}} .nx-form-input' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};' ],
382 ]
383 );
384
385 $this->add_control(
386 'nx_input_padding',
387 [
388 'label' => esc_html__( 'Padding', 'notificationx' ),
389 'type' => Controls_Manager::DIMENSIONS,
390 'size_units' => [ 'px', 'em' ],
391 'selectors' => [ '{{WRAPPER}} .nx-form-input' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};' ],
392 ]
393 );
394
395 $this->add_control(
396 'nx_field_spacing',
397 [
398 'label' => esc_html__( 'Row Gap (Vertical)', 'notificationx' ),
399 'type' => Controls_Manager::SLIDER,
400 'size_units' => [ 'px' ],
401 'range' => [ 'px' => [ 'min' => 0, 'max' => 60 ] ],
402 'default' => [ 'unit' => 'px', 'size' => 14 ],
403 'selectors' => [ '{{WRAPPER}} .nx-form-rows' => 'row-gap: {{SIZE}}{{UNIT}};' ],
404 ]
405 );
406
407 $this->add_control(
408 'nx_column_gap',
409 [
410 'label' => esc_html__( 'Column Gap (Horizontal)', 'notificationx' ),
411 'type' => Controls_Manager::SLIDER,
412 'size_units' => [ 'px' ],
413 'range' => [ 'px' => [ 'min' => 0, 'max' => 60 ] ],
414 'default' => [ 'unit' => 'px', 'size' => 14 ],
415 'selectors' => [ '{{WRAPPER}} .nx-form-rows' => 'column-gap: {{SIZE}}{{UNIT}}; --nx-gap: {{SIZE}}{{UNIT}};' ],
416 ]
417 );
418
419 $this->end_controls_section();
420
421 // ── Style: Button ────────────────────────────────────────────────
422 $this->start_controls_section(
423 'section_style_button',
424 [ 'label' => esc_html__( 'Button', 'notificationx' ), 'tab' => Controls_Manager::TAB_STYLE ]
425 );
426
427 $this->add_group_control(
428 Group_Control_Typography::get_type(),
429 [ 'name' => 'nx_button_typography', 'selector' => '{{WRAPPER}} .nx-form-submit' ]
430 );
431
432 $this->start_controls_tabs( 'nx_button_tabs' );
433
434 $this->start_controls_tab( 'nx_button_tab_normal', [ 'label' => esc_html__( 'Normal', 'notificationx' ) ] );
435 $this->add_control(
436 'nx_button_color',
437 [ 'label' => esc_html__( 'Text Color', 'notificationx' ), 'type' => Controls_Manager::COLOR, 'default' => '#ffffff', 'selectors' => [ '{{WRAPPER}} .nx-form-submit' => 'color: {{VALUE}};' ] ]
438 );
439 $this->add_control(
440 'nx_button_bg',
441 [ 'label' => esc_html__( 'Background', 'notificationx' ), 'type' => Controls_Manager::COLOR, 'default' => '#2271b1', 'selectors' => [ '{{WRAPPER}} .nx-form-submit' => 'background-color: {{VALUE}};' ] ]
442 );
443 $this->end_controls_tab();
444
445 $this->start_controls_tab( 'nx_button_tab_hover', [ 'label' => esc_html__( 'Hover', 'notificationx' ) ] );
446 $this->add_control(
447 'nx_button_color_h',
448 [ 'label' => esc_html__( 'Text Color', 'notificationx' ), 'type' => Controls_Manager::COLOR, 'selectors' => [ '{{WRAPPER}} .nx-form-submit:hover' => 'color: {{VALUE}};' ] ]
449 );
450 $this->add_control(
451 'nx_button_bg_h',
452 [ 'label' => esc_html__( 'Background', 'notificationx' ), 'type' => Controls_Manager::COLOR, 'selectors' => [ '{{WRAPPER}} .nx-form-submit:hover' => 'background-color: {{VALUE}};' ] ]
453 );
454 $this->end_controls_tab();
455
456 $this->end_controls_tabs();
457
458 $this->add_group_control(
459 Group_Control_Border::get_type(),
460 [ 'name' => 'nx_button_border', 'selector' => '{{WRAPPER}} .nx-form-submit' ]
461 );
462
463 $this->add_control(
464 'nx_button_radius',
465 [
466 'label' => esc_html__( 'Border Radius', 'notificationx' ),
467 'type' => Controls_Manager::DIMENSIONS,
468 'size_units' => [ 'px', '%' ],
469 'selectors' => [ '{{WRAPPER}} .nx-form-submit' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};' ],
470 ]
471 );
472
473 $this->add_control(
474 'nx_button_padding',
475 [
476 'label' => esc_html__( 'Padding', 'notificationx' ),
477 'type' => Controls_Manager::DIMENSIONS,
478 'size_units' => [ 'px', 'em' ],
479 'default' => [ 'top' => '12', 'right' => '20', 'bottom' => '12', 'left' => '20', 'unit' => 'px', 'isLinked' => false ],
480 'selectors' => [ '{{WRAPPER}} .nx-form-submit' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};' ],
481 ]
482 );
483
484 $this->add_responsive_control(
485 'nx_button_align',
486 [
487 'label' => esc_html__( 'Alignment', 'notificationx' ),
488 'type' => Controls_Manager::CHOOSE,
489 'options' => [
490 'flex-start' => [ 'title' => esc_html__( 'Left', 'notificationx' ), 'icon' => 'eicon-text-align-left' ],
491 'center' => [ 'title' => esc_html__( 'Center', 'notificationx' ), 'icon' => 'eicon-text-align-center' ],
492 'flex-end' => [ 'title' => esc_html__( 'Right', 'notificationx' ), 'icon' => 'eicon-text-align-right' ],
493 'stretch' => [ 'title' => esc_html__( 'Justified', 'notificationx' ), 'icon' => 'eicon-text-align-justify' ],
494 ],
495 'default' => 'stretch',
496 'selectors' => [ '{{WRAPPER}} .nx-form-actions' => 'justify-content: {{VALUE}};' ],
497 ]
498 );
499
500 $this->end_controls_section();
501 }
502
503 /**
504 * Build the class string for a row given per-breakpoint width settings.
505 *
506 * @param array $s Settings array.
507 * @param string $base_key The control base name (e.g. `nx_name_width`).
508 * @return string
509 */
510 private function row_width_classes( $s, $base_key ) {
511 $classes = [ 'nx-form-row' ];
512 $map = [
513 '' => $s[ $base_key ] ?? '100',
514 'tablet-' => $s[ $base_key . '_tablet' ] ?? '',
515 'mobile-' => $s[ $base_key . '_mobile' ] ?? '',
516 ];
517 foreach ( $map as $prefix => $val ) {
518 if ( $val !== '' && $val !== null ) {
519 $classes[] = 'nx-w-' . $prefix . $val;
520 }
521 }
522 return implode( ' ', array_map( 'sanitize_html_class', $classes ) );
523 }
524
525 protected function render() {
526 $s = $this->get_settings_for_display();
527
528 $campaign_id = absint( $s['nx_campaign_id'] ?? 0 );
529 $rest_url = esc_url_raw( rest_url( 'notificationx/v1/popup-submit' ) );
530
531 $form_id = 'nx-form-' . esc_attr( $this->get_id() );
532 $show_name = ! empty( $s['nx_show_name'] );
533 $show_email = ! empty( $s['nx_show_email'] );
534 $show_message = ! empty( $s['nx_show_message'] );
535
536 // Don't render the form at all if no campaign is selected — show a
537 // friendly editor-only notice.
538 if ( ! $campaign_id ) {
539 if ( \Elementor\Plugin::$instance->editor->is_edit_mode() ) {
540 printf(
541 '<div class="nx-form-notice">%s</div>',
542 esc_html__( 'Select a NotificationX campaign in the Form Settings to start collecting entries.', 'notificationx' )
543 );
544 }
545 return;
546 }
547 ?>
548 <div class="nx-form-wrapper">
549
550 <?php if ( ! empty( $s['nx_form_title'] ) ) : ?>
551 <h3 class="nx-form-title"><?php echo esc_html( $s['nx_form_title'] ); ?></h3>
552 <?php endif; ?>
553
554 <form
555 id="<?php echo esc_attr( $form_id ); ?>"
556 class="nx-form"
557 data-nx-id="<?php echo esc_attr( $campaign_id ); ?>"
558 data-rest-url="<?php echo esc_attr( $rest_url ); ?>"
559 data-success="<?php echo esc_attr( $s['nx_success_message'] ?? '' ); ?>"
560 data-error="<?php echo esc_attr( $s['nx_error_message'] ?? '' ); ?>"
561 novalidate
562 >
563 <div class="nx-form-rows">
564
565 <?php if ( $show_name ) : ?>
566 <div class="<?php echo esc_attr( $this->row_width_classes( $s, 'nx_name_width' ) ); ?>">
567 <?php if ( ! empty( $s['nx_name_label'] ) ) : ?>
568 <label class="nx-form-label" for="<?php echo esc_attr( $form_id ); ?>-name">
569 <?php echo esc_html( $s['nx_name_label'] ); ?>
570 <?php if ( ! empty( $s['nx_name_required'] ) ) echo ' <span class="nx-form-required">*</span>'; ?>
571 </label>
572 <?php endif; ?>
573 <input
574 type="text"
575 id="<?php echo esc_attr( $form_id ); ?>-name"
576 name="name"
577 class="nx-form-input"
578 placeholder="<?php echo esc_attr( $s['nx_name_placeholder'] ?? '' ); ?>"
579 <?php if ( ! empty( $s['nx_name_required'] ) ) echo 'required'; ?>
580 >
581 </div>
582 <?php endif; ?>
583
584 <?php if ( $show_email ) : ?>
585 <div class="<?php echo esc_attr( $this->row_width_classes( $s, 'nx_email_width' ) ); ?>">
586 <?php if ( ! empty( $s['nx_email_label'] ) ) : ?>
587 <label class="nx-form-label" for="<?php echo esc_attr( $form_id ); ?>-email">
588 <?php echo esc_html( $s['nx_email_label'] ); ?>
589 <?php if ( ! empty( $s['nx_email_required'] ) ) echo ' <span class="nx-form-required">*</span>'; ?>
590 </label>
591 <?php endif; ?>
592 <input
593 type="email"
594 id="<?php echo esc_attr( $form_id ); ?>-email"
595 name="email"
596 class="nx-form-input"
597 placeholder="<?php echo esc_attr( $s['nx_email_placeholder'] ?? '' ); ?>"
598 <?php if ( ! empty( $s['nx_email_required'] ) ) echo 'required'; ?>
599 >
600 </div>
601 <?php endif; ?>
602
603 <?php if ( $show_message ) : ?>
604 <div class="<?php echo esc_attr( $this->row_width_classes( $s, 'nx_message_width' ) ); ?>">
605 <?php if ( ! empty( $s['nx_message_label'] ) ) : ?>
606 <label class="nx-form-label" for="<?php echo esc_attr( $form_id ); ?>-message">
607 <?php echo esc_html( $s['nx_message_label'] ); ?>
608 <?php if ( ! empty( $s['nx_message_required'] ) ) echo ' <span class="nx-form-required">*</span>'; ?>
609 </label>
610 <?php endif; ?>
611 <textarea
612 id="<?php echo esc_attr( $form_id ); ?>-message"
613 name="message"
614 class="nx-form-input nx-form-textarea"
615 rows="<?php echo absint( $s['nx_message_rows'] ?? 4 ); ?>"
616 placeholder="<?php echo esc_attr( $s['nx_message_placeholder'] ?? '' ); ?>"
617 <?php if ( ! empty( $s['nx_message_required'] ) ) echo 'required'; ?>
618 ></textarea>
619 </div>
620 <?php endif; ?>
621
622 <div class="<?php echo esc_attr( $this->row_width_classes( $s, 'nx_submit_width' ) ); ?> nx-form-actions">
623 <button type="submit" class="nx-form-submit">
624 <?php echo esc_html( $s['nx_submit_text'] ?? __( 'Submit', 'notificationx' ) ); ?>
625 </button>
626 </div>
627
628 </div>
629
630 <div class="nx-form-message" role="status" aria-live="polite"></div>
631 </form>
632 </div>
633 <?php
634 }
635 }
636