PluginProbe
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards / 5.5.84
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards v5.5.84
5.5.84 5.5.83 5.5.82 5.5.81 5.5.80 5.5.79 5.5.77 5.5.76 5.5.75 5.5.73 5.5.72 5.5.22 5.5.23 5.5.29 5.5.3 5.5.31 5.5.32 5.5.34 5.5.35 5.5.36 5.5.37 5.5.4 5.5.40 5.5.41 5.5.42 All 160 releases
wp-data-access / WPDataAccess / Simple_Form / WPDA_Simple_Form_Item.php

WPDA_Simple_Form_Item.php in WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards 5.5.84, at WPDataAccess/Simple_Form/WPDA_Simple_Form_Item.php

1,021 lines 22.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Suppress "error - 0 - No summary was found for this file" on phpdoc generation
5 *
6 * @package WPDataAccess\Simple_Form
7 */
8
9 namespace WPDataAccess\Simple_Form {
10
11 use WPDataAccess\Utilities\WPDA_Message_Box;
12 use WPDataAccess\WPDA;
13
14 /**
15 * Class WPDA_Simple_Form_Item
16 *
17 * Simple forms consist of items. Items correspond with table columns. Basically an item is generated for every
18 * table column in the base table. Class WPDA_Simple_Form_Item handles a database column as a standard text item.
19 *
20 * It's possible to add dummy columns. Values for dummy columns however are lost when data is saved.
21 *
22 * Check out {@see WPDA_Simple_Form} to see how to use simple form items.
23 *
24 * @author Peter Schulz
25 * @since 1.0.0
26 */
27 class WPDA_Simple_Form_Item {
28
29 /**
30 * Database column name
31 *
32 * @var string
33 */
34 protected $item_name;
35
36 /**
37 * MySQL data type
38 *
39 * @var string
40 */
41 protected $data_type;
42
43 /**
44 * Item label
45 *
46 * @var string
47 */
48 protected $item_label;
49
50 /**
51 * Current column value in the database
52 *
53 * @var mixed
54 */
55 protected $item_value;
56
57 /**
58 * Default value
59 *
60 * @var mixed
61 */
62 protected $item_default_value;
63
64 /**
65 * Database column specific info
66 *
67 * Like auto_increment, on update, etc
68 *
69 * @var string
70 */
71 protected $item_extra;
72
73 /**
74 * Enum values for column or empty
75 *
76 * @var array
77 */
78 protected $item_enum;
79
80 /**
81 * Enum options for column or empty
82 *
83 * @var array
84 */
85 protected $item_enum_options;
86
87 /**
88 * Enum text for column or empty
89 *
90 * @var array
91 */
92 protected $item_enum_text;
93
94 /**
95 * Database column type
96 *
97 * Column type offers more info than data type, like column length or values for enum types.
98 *
99 * @var string
100 */
101 protected $column_type;
102
103 /**
104 * Icon type
105 *
106 * @var string
107 */
108 protected $item_icon_type;
109
110 /**
111 * Array of events
112 *
113 * Add event to item for example: ["onclick" => "check_item_value()"]
114 *
115 * @var array
116 */
117 protected $item_event;
118
119 /**
120 * Item specific Javascript code
121 *
122 * Code is added to the end of the form.
123 *
124 * @var string
125 */
126 protected $item_js;
127
128 /**
129 * Show item icon (data type)
130 *
131 * TRUE = icon is shown after item, FALSE = hide icon (default FALSE)
132 *
133 * @var boolean
134 */
135 protected $item_hide_icon;
136
137 /**
138 * Item CSS class
139 *
140 * @var string
141 */
142 protected $item_class;
143
144 /**
145 * TRUE = item not shown, FALSE = item shown
146 *
147 * @var boolean
148 */
149 protected $hide_item;
150
151 /**
152 * TRUE = item not shown on init, FALSE = item shown on init
153 *
154 * @var boolean
155 */
156 protected $hide_item_init = false;
157
158 /**
159 * TRUE = null values are allowed, FALSE = no null values allowed
160 *
161 * @var boolean
162 */
163 protected $is_nullable;
164
165 /**
166 * TRUE = is auto_increment column
167 *
168 * @var boolean
169 */
170 protected $is_auto_increment = false;
171
172 /**
173 * TRUE = column is part of primary key, FALSE = column is not part of primary key
174 *
175 * @var boolean
176 */
177 protected $is_key_column;
178
179 /**
180 * TRUE = column is part of foreign key, FALSE = column is not part of foreign key
181 *
182 * @var boolean
183 */
184 protected $is_foreign_key_column = false;
185
186 /**
187 * Set to true to make item readonly
188 *
189 * @var boolean
190 */
191 protected $is_readonly = false;
192
193 /**
194 * Context variable to keep logic for showing items maintainable
195 *
196 * @var string
197 */
198 protected $show_context_action;
199
200 /**
201 * Context variable to keep logic for showing items maintainable
202 *
203 * @var string
204 */
205 protected $show_context_update_keys_allowed;
206
207 /**
208 * Context variable to keep logic for showing items maintainable
209 *
210 * @var string
211 */
212 protected $show_context_column_value;
213
214 /**
215 * Context variable to keep logic for showing items maintainable
216 *
217 * @var string
218 */
219 protected $show_context_class_primary_key;
220
221 /**
222 * Context variable to keep logic for showing items maintainable
223 *
224 * @var string
225 */
226 protected $show_context_item_events;
227
228 /**
229 * Item placeholder
230 *
231 * @var string
232 */
233 protected $item_placeholder = '';
234
235 /**
236 * Max length text column
237 *
238 * @var int
239 */
240 protected $character_maximum_length;
241
242 /**
243 * NUmeric precision
244 *
245 * @var int
246 */
247 protected $numeric_precision;
248
249 /**
250 * Numeric scale
251 *
252 * @var int
253 */
254 protected $numeric_scale;
255
256 public $checkbox_value_on; // Needed for Data Publisher
257
258 /**
259 * WPDA_Simple_Form_Item constructor
260 *
261 * Declare item with all its properties.
262 *
263 * @param array $args [
264 *
265 * 'item_name' => item name
266 *
267 * 'data_type' => data type
268 *
269 * 'item_label' => label
270 *
271 * 'item_value' => value (in database)
272 *
273 * 'item_default_value' => default value
274 *
275 * 'item_extra' => check column extra in information_schema.columns
276 *
277 * 'item_enum' => enum (if applicable)
278 *
279 * 'item_enum_options' => enum options (if applicable)
280 *
281 * 'column_type' => type
282 *
283 * 'item_event' => JS event(s)
284 *
285 * 'item_js' => JS code (global)
286 *
287 * 'item_hide_icon' => icon (showing data type)
288 *
289 * 'item_class' => css class
290 *
291 * 'hide_item' => item visibility
292 *
293 * 'is_nullable' => allow null values?
294 *
295 * 'is_key_column' => is key column?
296 *
297 * 'character_maximum_length' => max width text column
298 *
299 * 'numeric_precision' => numeric precision numeric column
300 *
301 * 'numeric_scale' => numeric scale numeric column
302 *
303 * ].
304 *
305 * @since 1.0.0
306 */
307 public function __construct( $args = array() ) {
308 if ( is_array( $args ) ) {
309 $args = wp_parse_args(
310 $args,
311 array(
312 'item_name' => '',
313 'data_type' => '',
314 'item_label' => '',
315 'item_value' => null,
316 'item_default_value' => null,
317 'item_extra' => '',
318 'item_enum' => '',
319 'item_enum_options' => '',
320 'item_enum_text' => '',
321 'column_type' => '',
322 'item_event' => '',
323 'item_js' => '',
324 'item_hide_icon' => false,
325 'item_class' => '',
326 'hide_item' => false,
327 'is_nullable' => null,
328 'is_key_column' => null,
329 'character_maximum_length' => 0,
330 'numeric_precision' => 0,
331 'numeric_scale' => 0,
332 )
333 );
334
335 if ( '' === $args['item_name'] ) {
336 // Without an item name it makes no sense to continue
337 wp_die( esc_attr__( 'ERROR: Wrong arguments [missing item name]', 'wp-data-access' ) );
338 }
339
340 if ( '' === $args['data_type'] ) {
341 // Without a data type it makes no sense to continue
342 wp_die( esc_attr__( 'ERROR: Wrong arguments [missing data type]', 'wp-data-access' ) );
343 }
344
345 $this->item_name = $args['item_name'];
346 $this->data_type = WPDA::get_type( $args['data_type'] );
347 $this->item_icon_type = $this->data_type;
348 $this->item_label = (string) $args['item_label']; // phpcs:ignore -- 8.1 proof
349 if ( null === $args['item_value'] ) {
350 $this->item_value = null;
351 } else {
352 $this->item_value = (string) $args['item_value']; // phpcs:ignore -- 8.1 proof
353 }
354 if (
355 'current_timestamp()' !== strtolower( (string) $args['item_default_value'] ) &&
356 'current_timestamp' !== strtolower( (string) $args['item_default_value'] )
357 ) {
358 $this->item_default_value = $args['item_default_value'];
359 }
360 $this->item_extra = $args['item_extra'];
361 if ( 'auto_increment' === $this->item_extra ) {
362 $this->is_auto_increment = true;
363 }
364 $this->item_enum = '';
365 $this->item_enum_options = '';
366 $this->item_enum_text = '';
367 if ( 'enum' === $this->data_type ) {
368 $this->item_enum = explode(
369 ',',
370 str_replace(
371 '\'',
372 '',
373 substr( substr( ( string ) $args['item_enum'], 5 ), 0, - 1 )
374 )
375 ); // phpcs:ignore -- 8.1 proof
376 }
377 if ( 'set' === $this->data_type ) {
378 $this->item_enum = explode(
379 ',',
380 str_replace(
381 '\'',
382 '',
383 substr( substr( ( string ) $args['item_enum'], 4 ), 0, - 1 )
384 )
385 ); // phpcs:ignore -- 8.1 proof
386 }
387 $this->column_type = $args['column_type'];
388 $this->item_event = $args['item_event'];
389 $this->item_js = $args['item_js'];
390 $this->item_hide_icon = $args['item_hide_icon'];
391 $this->item_class = $args['item_class'];
392 $this->hide_item = $args['hide_item'];
393 $this->is_nullable = $args['is_nullable'];
394 $this->is_key_column = $args['is_key_column'];
395
396 // Column length and numeric scale and precision
397 $this->character_maximum_length = $args['character_maximum_length'];
398 $this->numeric_precision = $args['numeric_precision'];
399 $this->numeric_scale = $args['numeric_scale'];
400
401 } elseif ( is_object( $args ) ) {
402 if ( 0 <= strpos( self::class, 'WPDA_Simple_Form_Item' ) ) {
403 foreach ( $args as $property => $value ) {
404 $this->$property = $value;
405 }
406 } else {
407 wp_die( esc_attr__( 'Class must be of (sub)type WPDA_Simple_Form_Item', 'wp-data-access' ) );
408 }
409 } else {
410 wp_die( esc_attr__( 'Could not create form item instance [argument must be array or object]', 'wp-data-access' ) );
411 }
412 }
413
414 /**
415 * Show item row
416 *
417 * @param string $action Requested action
418 * @param string $update_keys_allowed TRUE = allow key updates
419 */
420 public function show( $action, $update_keys_allowed ) {
421 if ( $this->hide_item && ! $this->is_auto_increment && ! $this->is_foreign_key_column ) {
422 if ( 'new' === $action && '' !== $this->get_item_default_value() && null !== $this->get_item_default_value() ) {
423 // Add hidden item to apply default value
424 } else {
425 // Do not show item, do not add hidden item to form, user is not allowed to view this item
426 return;
427 }
428 }
429
430 // Set context variables
431 $this->show_context_action = $action;
432 $this->show_context_update_keys_allowed = $update_keys_allowed;
433
434 if ( 'row' === substr( $this->item_class, 0, 3 ) ) {
435 // Process row level class
436 $row_class = $this->item_class;
437 $this->item_class = '';
438 } else {
439 $row_class = '';
440 }
441
442 if ( true === $this->hide_item_init || true === $this->hide_item ) {
443 ?>
444 <tr style='display:none'<?php echo '' === $row_class ? '' : ' class="' . esc_attr( $row_class ) . '"'; ?>>
445 <?php
446 } else {
447 ?>
448 <tr <?php echo '' === $row_class ? '' : ' class="' . esc_attr( $row_class ) . '"'; ?>>
449 <?php
450 }
451
452 $label = explode( '|', esc_attr( $this->item_label ) ); // phpcs:ignore -- 8.1 proof
453 $label_before = $label[0];
454 $label_after = '';
455 if ( isset( $label[1] ) ) {
456 $label_after = $label[1];
457 }
458
459 if ( 'view' === $action ) {
460 $label_title = ' ';
461 } else {
462 $label_title = $label_before . ' ';
463 $label_title .= 'NO' === $this->is_nullable ? __( 'must be entered', 'wp-data-access' ) : __( 'is optional', 'wp-data-access' );
464 }
465 ?>
466 <td class="label">
467 <label for="<?php echo esc_attr( $this->item_name ); ?>"
468 title="<?php echo esc_attr( $label_title ); ?>"
469 class="wpda_tooltip"
470 >
471 <?php echo 'NO' === $this->is_nullable ? '*' : ''; ?>
472 <?php echo esc_attr( $label_before ); ?>
473 </label>
474 </td>
475 <td class="data">
476 <?php
477 // Get column value
478 $this->show_context_column_value = esc_html( str_replace( '&', '&amp;', (string) $this->item_value ) );
479
480 // Set primary key class(es)
481 $this->show_context_class_primary_key = $this->is_key_column ? 'wpda_primary_key' : '';
482 if ( $this->is_auto_increment ) {
483 $this->show_context_class_primary_key .= ' auto_increment';
484 }
485
486 // Prepare events
487 $this->show_context_item_events = '';
488 if ( is_array( $this->item_event ) ) {
489 foreach ( $this->item_event as $event_name => $event_code ) {
490 $this->show_context_item_events .= "$event_name=$event_code ";
491 }
492 }
493
494 // Show item
495 $this->show_item();
496 ?>
497 <input type="hidden"
498 name="<?php echo esc_attr( $this->item_name ); ?>_old"
499 value="<?php echo $this->show_context_column_value; // phpcs:ignore WordPress.Security.EscapeOutput ?>"
500 />
501 <?php echo '' === $label_after ? '' : '<label>' . esc_attr( $label_after ) . '</label>'; ?>
502 </td>
503 <td class="icon">
504 <?php
505 // Add data type icon.
506 if ( ! $this->item_hide_icon ) {
507 $type_button = new WPDA_Simple_Form_Type_Icon( $this->item_name, $this->item_icon_type );
508 $type_button->show();
509 }
510 ?>
511 </td>
512 </tr>
513 <?php
514 }
515
516 /**
517 * Displays default text item
518 *
519 * Overwrite this method to define specific item processing like enum, set, image and so on.
520 */
521 protected function show_item() {
522 // Set column value.
523 if ( 'new' === $this->show_context_action ) {
524 // Check if there is a default value.
525 if ( $this->item_default_value !== null &&
526 strtolower( $this->item_default_value ) !== 'null' ) {
527 $this->show_context_column_value = $this->item_default_value;
528 }
529 }
530
531 // Add input box.
532 $data_type = $this->data_type;
533 if ( 'number' === $this->data_type ) {
534 if ( 0 < $this->numeric_scale ) {
535 $data_type = 'float';
536 }
537 }
538 ?>
539 <input name="<?php echo esc_attr( $this->item_name ); ?>"
540 id="<?php echo esc_attr( $this->item_name ); ?>"
541 type="text"
542 value="<?php echo $this->show_context_column_value; // phpcs:ignore WordPress.Security.EscapeOutput ?>"
543 data-db-is-null="<?php echo null === $this->item_value ? 'true' : 'false'; ?>"
544 class="wpda_data_type_<?php echo esc_attr( $data_type ); ?> <?php echo esc_attr( $this->show_context_class_primary_key ); ?> <?php echo esc_attr( $this->item_class ); ?> <?php
545 if ( 'NO' === $this->is_nullable && ! $this->is_auto_increment ) {
546 echo 'wpda_not_null';
547 }
548 ?>"
549 <?php
550 switch( $this->data_type ) {
551 case 'string':
552 echo 'maxlength="' . esc_attr( $this->character_maximum_length ) . '"';
553 break;
554 case 'number':
555 echo 'data-number-format="' . esc_attr( $this->numeric_precision ) . ',' . esc_attr( $this->numeric_scale ) . '"';
556 }
557 ?>
558 <?php echo $this->is_readonly ? ' readonly' : ''; ?>
559 <?php echo esc_attr( $this->show_context_item_events ); ?>
560 placeholder="<?php echo esc_attr( $this->item_placeholder ); ?>"
561 />
562 <?php
563 if ( 'string' === $this->data_type ) {
564 ?>
565 <input name="<?php echo esc_attr( $this->item_name ); ?>_db_is_null"
566 value="<?php echo null === $this->item_value ? 'true' : 'false'; ?>"
567 type="hidden"
568 />
569 <?php
570 }
571 }
572
573 /**
574 * Het item name
575 *
576 * @return string
577 * @since 1.0.0
578 */
579 public function get_item_name() {
580
581 return $this->item_name;
582
583 }
584
585 /**
586 * Get item data type
587 *
588 * @return string
589 * @since 1.0.0
590 */
591 public function get_data_type() {
592
593 return $this->data_type;
594
595 }
596
597 /**
598 * Get item label
599 *
600 * @return string
601 * @since 1.0.0
602 */
603 public function get_item_label() {
604
605 return $this->item_label;
606
607 }
608
609 /**
610 * Get item value
611 *
612 * @return mixed
613 * @since 1.0.0
614 */
615 public function get_item_value() {
616
617 return $this->item_value;
618
619 }
620
621 /**
622 * Get item default value
623 *
624 * @return mixed
625 * @since 1.0.0
626 */
627 public function get_item_default_value() {
628
629 return $this->item_default_value;
630
631 }
632
633 /**
634 * Get item 'extra' info
635 *
636 * @return mixed
637 * @see WPDA_Simple_Form_Item::$item_extra
638 *
639 * @since 1.0.0
640 */
641 public function get_item_extra() {
642
643 return $this->item_extra;
644
645 }
646
647 /**
648 * Get enum values or empty
649 *
650 * @return array
651 * @since 1.0.0
652 */
653 public function get_item_enum() {
654
655 return $this->item_enum;
656
657 }
658
659 /**
660 * Get enum options or empty
661 *
662 * @return array
663 * @since 1.6.9
664 */
665 public function get_item_enum_options() {
666
667 return $this->item_enum_options;
668
669 }
670
671 /**
672 * Get enum text or empty
673 *
674 * @return array
675 * @since 1.6.9
676 */
677 public function get_item_enum_text() {
678
679 return $this->item_enum_text;
680
681 }
682
683 /**
684 * Get column type
685 *
686 * @return string
687 * @since 1.0.0
688 */
689 public function get_column_type() {
690
691 return $this->column_type;
692
693 }
694
695 /**
696 * Get item event
697 *
698 * @return String
699 * @since 1.0.0
700 */
701 public function get_item_event() {
702
703 return $this->item_event;
704
705 }
706
707 /**
708 * Get item Javascript code
709 *
710 * @return mixed
711 * @since 1.0.0
712 */
713 public function get_item_js() {
714
715 return $this->item_js;
716
717 }
718
719 /**
720 * Hide icon?
721 *
722 * @return boolean
723 * @since 1.0.0
724 */
725 public function get_item_hide_icon() {
726
727 return $this->item_hide_icon;
728
729 }
730
731 /**
732 * Get item CSS class
733 *
734 * @return string
735 * @since 1.0.0
736 */
737 public function get_item_class() {
738
739 return $this->item_class;
740
741 }
742
743 /**
744 * Get item visibility
745 *
746 * @return boolean
747 * @since 1.6.9
748 */
749 public function get_hide_item() {
750
751 return $this->hide_item;
752
753 }
754
755 /**
756 * Null values allowed?
757 *
758 * @return boolean
759 * @since 2.0.0
760 */
761 public function is_nullable() {
762
763 return $this->is_nullable;
764
765 }
766
767 /**
768 * Is column part of the primary key?
769 *
770 * @return boolean
771 * @since 2.0.0
772 */
773 public function is_key_column() {
774
775 return $this->is_key_column;
776
777 }
778
779 /**
780 * Item value
781 *
782 * @param string $value Item value
783 */
784 public function set_item_value( $value ) {
785
786 $this->item_value = $value;
787
788 }
789
790 /**
791 * Item label
792 *
793 * @param string $label Item label
794 */
795 public function set_label( $label ) {
796
797 $this->item_label = $label;
798
799 }
800
801 /**
802 * Set item default value
803 *
804 * @param string $item_default_value Default value
805 *
806 * @since 1.6.2
807 */
808 public function set_item_default_value( $item_default_value ) {
809
810 $this->item_default_value = $item_default_value;
811
812 }
813
814 /**
815 * Set item CSS class
816 *
817 * @param string $item_class HTML class name
818 *
819 * @since 1.6.2
820 */
821 public function set_item_class( $item_class ) {
822
823 $this->item_class = $item_class;
824
825 }
826
827 /**
828 * Set item visibility
829 *
830 * @param boolean $hide_item TRUE = hide item
831 *
832 * @since 1.6.9
833 */
834 public function set_hide_item( $hide_item ) {
835
836 $this->hide_item = $hide_item;
837
838 }
839
840 /**
841 * Set item js code
842 *
843 * @param string $item_js Item specific javascript code
844 *
845 * @since 1.6.9
846 */
847 public function set_item_js( $item_js ) {
848
849 $this->item_js = $item_js;
850
851 }
852
853 /**
854 * Set item enum
855 *
856 * @param string $item_enum Item enum value list
857 *
858 * @since 1.6.9
859 */
860 public function set_enum( $item_enum ) {
861
862 $this->item_enum = $item_enum;
863
864 }
865
866 /**
867 * Set item enum options
868 *
869 * @param string $item_enum_options Item enum option list
870 *
871 * @since 1.6.9
872 */
873 public function set_enum_options( $item_enum_options ) {
874
875 $this->item_enum_options = $item_enum_options;
876
877 }
878
879 /**
880 * Set item enum text
881 *
882 * @param string $item_enum_text Item enum text list.
883 *
884 * @since 1.6.9
885 */
886 public function set_enum_text( $item_enum_text ) {
887
888 $this->item_enum_text = $item_enum_text;
889
890 }
891
892 /**
893 * Set item data_type
894 *
895 * @param string $data_type Item data type
896 *
897 * @since 1.6.9
898 */
899 public function set_data_type( $data_type ) {
900
901 $this->data_type = $data_type;
902
903 }
904
905 /**
906 * Set item visibility
907 *
908 * @param boolean $item_hide_icon TRUE = hide type icon behind text field
909 *
910 * @since 2.0.8
911 */
912 public function set_item_hide_icon( $item_hide_icon ) {
913
914 $this->item_hide_icon = $item_hide_icon;
915
916 }
917
918 /**
919 * Set item is key column
920 *
921 * @param boolean $is_key_column TRUE|FALSE
922 */
923 public function set_is_key_column( $is_key_column ) {
924
925 $this->is_key_column = $is_key_column;
926
927 }
928
929 /**
930 * Set item is foreign key column
931 *
932 * @param boolean $is_foreign_key_column TRUE|FALSE
933 */
934 public function set_foreign_key_column( $is_foreign_key_column ) {
935
936 $this->is_foreign_key_column = $is_foreign_key_column;
937
938 }
939
940 /**
941 * Change item readonly property
942 *
943 * @param boolean $is_readonly TRUE|FALSE
944 * @return void
945 */
946 public function set_readonly( $is_readonly ) {
947 $this->is_readonly = $is_readonly;
948 }
949
950 /**
951 * Set item visibility on initialization
952 *
953 * @param boolean $hide_item_init TRUE = hide item init
954 *
955 * @since 1.6.9
956 */
957 public function set_hide_item_init( $hide_item_init ) {
958
959 $this->hide_item_init = $hide_item_init;
960
961 }
962
963 /**
964 * Check if item is valid
965 *
966 * @param $pre_insert
967 *
968 * @return bool
969 */
970 public function is_valid( $pre_insert = false ) {
971 if ( $this->is_auto_increment && $pre_insert ) {
972 return true;
973 }
974
975 if ( 'NO' === $this->is_nullable ) {
976 // Empty values are not allowed for this column: check value.
977 if ( '' === $this->item_value ) {
978 if ( isset( $_REQUEST[ "{$this->item_name}_db_is_null" ] ) && 'false' === strtolower( $_REQUEST[ "{$this->item_name}_db_is_null" ] ) ) { // phpcs:ignore
979 // Allow update if original column already was an empty string
980 return true;
981 }
982
983 // No value: inform user and set validation to failed.
984 $msg = new WPDA_Message_Box(
985 array(
986 'message_text' => ucfirst( str_replace( '_', ' ', $this->item_name ) ) .
987 ' ' . __( 'must be entered', 'wp-data-access' ),
988 'message_type' => 'error',
989 'message_is_dismissible' => false,
990 )
991 );
992 $msg->box();
993
994 return false;
995 }
996 }
997
998 if ( 'number' === $this->data_type ) {
999 if ( '' !== $this->item_value && null !== $this->item_value && ! is_numeric( $this->item_value ) ) {
1000 // Value is not numeric: inform user and set validation to failed.
1001 $msg = new WPDA_Message_Box(
1002 array(
1003 'message_text' => ucfirst( str_replace( '_', ' ', $this->item_name ) ) .
1004 ' ' . __( 'must be numeric', 'wp-data-access' ),
1005 'message_type' => 'error',
1006 'message_is_dismissible' => false,
1007 )
1008 );
1009 $msg->box();
1010
1011 return false;
1012 }
1013 }
1014
1015 return true;
1016 }
1017
1018 }
1019
1020 }
1021