PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.22
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.22
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | classes/models/FrmEntryValidate.php +2 -131 6.266.22 View file →
@@ -14,9 +14,8 @@
14 14
15 15 /**
16 16 * @param array $values
17 17 * @param bool|string[] $exclude
18 - *
19 18 * @return array
20 19 */
21 20 public static function validate( $values, $exclude = false ) {
22 21 FrmEntry::sanitize_entry_post( $values );
@@ -84,13 +83,8 @@
84 83 $_POST['item_meta'] = array();
85 84 }
86 85 }
87 86
88 - /**
89 - * @param array $values
90 - *
91 - * @return void
92 - */
93 87 private static function set_item_key( &$values ) {
94 88 if ( ! isset( $values['item_key'] ) || $values['item_key'] == '' ) {
95 89 global $wpdb;
96 90 $values['item_key'] = FrmAppHelper::get_unique_key( '', $wpdb->prefix . 'frm_items', 'item_key' );
@@ -97,14 +91,8 @@
97 91 $_POST['item_key'] = $values['item_key'];
98 92 }
99 93 }
100 94
101 - /**
102 - * @param array $values
103 - * @param array|string $exclude
104 - *
105 - * @return array
106 - */
107 95 private static function get_fields_to_validate( $values, $exclude ) {
108 96 $where = apply_filters( 'frm_posted_field_ids', array( 'fi.form_id' => $values['form_id'] ) );
109 97
110 98 // Don't get subfields
@@ -127,16 +115,8 @@
127 115 */
128 116 return apply_filters( 'frm_fields_to_validate', $fields, compact( 'values', 'exclude', 'where' ) );
129 117 }
130 118
131 - /**
132 - * @param object $posted_field
133 - * @param array $errors
134 - * @param array $values
135 - * @param array $args
136 - *
137 - * @return void
138 - */
139 119 public static function validate_field( $posted_field, &$errors, $values, $args = array() ) {
140 120 $defaults = array(
141 121 'id' => $posted_field->id,
142 122 // The id of the repeat or embed form.
@@ -149,9 +129,9 @@
149 129 );
150 130 $args = wp_parse_args( $args, $defaults );
151 131
152 132 if ( empty( $args['parent_field_id'] ) ) {
153 - $value = $values['item_meta'][ $args['id'] ] ?? '';
133 + $value = isset( $values['item_meta'][ $args['id'] ] ) ? $values['item_meta'][ $args['id'] ] : '';
154 134 } else {
155 135 // value is from a nested form
156 136 $value = $values;
157 137 }
@@ -161,9 +141,8 @@
161 141
162 142 self::maybe_clear_value_for_default_blank_setting( $posted_field, $value );
163 143
164 144 $should_trim = is_array( $value ) && count( $value ) == 1 && isset( $value[0] ) && $posted_field->type !== 'checkbox';
165 -
166 145 if ( $should_trim ) {
167 146 $value = reset( $value );
168 147 }
169 148
@@ -236,9 +215,8 @@
236 215 *
237 216 * @param stdClass $field
238 217 * @param array|string $value
239 218 * @param array $options
240 - *
241 219 * @return bool
242 220 */
243 221 private static function option_is_valid( $field, $value, $options ) {
244 222 if ( '' === $value ) {
@@ -244,14 +222,8 @@
244 222 if ( '' === $value ) {
245 223 return true;
246 224 }
247 225
248 - $field_object = FrmFieldFactory::get_field_type( $field->type, $field );
249 -
250 - if ( ! $field_object->field_type_has_options_settings() ) {
251 - return true;
252 - }
253 -
254 226 if ( in_array( $field->type, array( 'likert', 'ranking' ), true ) ) {
255 227 // Ignore these field types automatically.
256 228 return true;
257 229 }
@@ -282,21 +254,18 @@
282 254 $option_value = $option;
283 255 }
284 256
285 257 $match = trim( $current_value ) === trim( $option_value );
286 -
287 258 if ( $match ) {
288 259 break;
289 260 }
290 261
291 262 $match = trim( $current_value ) === trim( do_shortcode( $option_value ) );
292 -
293 263 if ( $match ) {
294 264 break;
295 265 }
296 266
297 267 $match = self::is_filtered_match( $current_value, $option_value );
298 -
299 268 if ( $match ) {
300 269 break;
301 270 }
302 271
@@ -301,9 +270,8 @@
301 270 }
302 271
303 272 if ( is_numeric( $current_value ) ) {
304 273 $match = (int) $current_value === (int) $option_value;
305 -
306 274 if ( $match ) {
307 275 break;
308 276 }
309 277 }
@@ -325,21 +293,17 @@
325 293 * @since 6.22
326 294 *
327 295 * @param string $value
328 296 * @param string $option_value
329 - *
330 297 * @return bool
331 298 */
332 299 private static function is_filtered_match( $value, $option_value ) {
333 300 // First remove the wpautop filter so it doesn't add extra tags to $option_value.
334 301 $filter_priority = has_filter( 'the_content', 'wpautop' );
335 -
336 302 if ( is_numeric( $filter_priority ) ) {
337 303 remove_filter( 'the_content', 'wpautop', $filter_priority );
338 304 }
339 -
340 305 $filtered_option = apply_filters( 'the_content', $option_value );
341 -
342 306 if ( is_numeric( $filter_priority ) ) {
343 307 add_filter( 'the_content', 'wpautop', $filter_priority );
344 308 }
345 309 return trim( $value ) === trim( $filtered_option );
@@ -350,11 +314,8 @@
350 314 * This is to help avoid issues where the options could be based on a URL param for example.
351 315 *
352 316 * @since 6.21
353 317 *
354 - * @param object $field_object The field object.
355 - * @param array|string $value The value to validate.
356 - *
357 318 * @return bool
358 319 */
359 320 private static function options_are_dynamic_based_on_hook( $field_object, $value ) {
360 321 $values = (array) $field_object;
@@ -367,9 +328,8 @@
367 328 $option_value = $separate_value ? $option['value'] : $option['label'];
368 329 } else {
369 330 $option_value = $option;
370 331 }
371 -
372 332 $option_value = do_shortcode( $option_value );
373 333 return $option_value;
374 334 };
375 335
@@ -385,14 +345,11 @@
385 345 * @since 5.2.02
386 346 *
387 347 * @param array|string $value Field value.
388 348 * @param object $field Field object.
389 - *
390 - * @return void
391 349 */
392 350 private static function maybe_add_item_name( $value, $field ) {
393 351 $item_name = false;
394 -
395 352 if ( 'name' === $field->type ) {
396 353 $field_obj = FrmFieldFactory::get_field_object( $field );
397 354 $item_name = $field_obj->get_display_value( $value );
398 355 } elseif ( 'text' === $field->type ) {
@@ -409,14 +366,11 @@
409 366 * Set $value to an empty string if it matches its label
410 367 *
411 368 * @param object $field
412 369 * @param string $value
413 - *
414 - * @return void
415 370 */
416 371 private static function maybe_clear_value_for_default_blank_setting( $field, &$value ) {
417 372 $position = FrmField::get_option( $field, 'label' );
418 -
419 373 if ( ! $position ) {
420 374 $position = FrmStylesController::get_style_val( 'position', $field->form_id );
421 375 }
422 376
@@ -424,16 +378,8 @@
424 378 $value = '';
425 379 }
426 380 }
427 381
428 - /**
429 - * @param array $errors
430 - * @param object $posted_field
431 - * @param mixed $value
432 - * @param array $args
433 - *
434 - * @return void
435 - */
436 382 public static function validate_field_types( &$errors, $posted_field, $value, $args ) {
437 383 $field_obj = FrmFieldFactory::get_field_object( $posted_field );
438 384 $args['value'] = $value;
439 385 $args['errors'] = $errors;
@@ -438,22 +384,13 @@
438 384 $args['value'] = $value;
439 385 $args['errors'] = $errors;
440 386
441 387 $new_errors = $field_obj->validate( $args );
442 -
443 388 if ( ! empty( $new_errors ) ) {
444 389 $errors = array_merge( $errors, $new_errors );
445 390 }
446 391 }
447 392
448 - /**
449 - * @param array $errors
450 - * @param object $field
451 - * @param string $value
452 - * @param array $args
453 - *
454 - * @return void
455 - */
456 393 public static function validate_phone_field( &$errors, $field, $value, $args ) {
457 394 $format_value = FrmField::get_option( $field, 'format' );
458 395
459 396 if ( $field->type === 'phone' || ( $field->type === 'text' && $format_value && ! FrmCurrencyHelper::is_currency_format( $format_value ) ) ) {
@@ -464,13 +401,8 @@
464 401 }
465 402 }
466 403 }
467 404
468 - /**
469 - * @param object $field
470 - *
471 - * @return string
472 - */
473 405 public static function phone_format( $field ) {
474 406 if ( FrmField::is_option_empty( $field, 'format' ) ) {
475 407 $pattern = self::default_phone_format();
476 408 } else {
@@ -493,10 +425,8 @@
493 425 }
494 426
495 427 /**
496 428 * @since 3.01
497 - *
498 - * @return string
499 429 */
500 430 private static function default_phone_format() {
501 431 return '^((\+\d{1,3}(-|.| )?\(?\d\)?(-| |.)?\d{1,5})|(\(?\d{2,6}\)?))(-|.| )?(\d{3,4})(-|.| )?(\d{4})(( x| ext)\d{1,5}){0,1}$';
502 432 }
@@ -525,9 +455,8 @@
525 455
526 456 if ( strpos( $pattern, '\?' ) !== false ) {
527 457 $parts = explode( '\?', $pattern );
528 458 $pattern = '';
529 -
530 459 foreach ( $parts as $part ) {
531 460 if ( empty( $pattern ) ) {
532 461 $pattern .= $part;
533 462 } else {
@@ -534,9 +463,8 @@
534 463 $pattern .= '(' . $part . ')?';
535 464 }
536 465 }
537 466 }
538 -
539 467 $pattern = '^' . $pattern . '$';
540 468
541 469 return $pattern;
542 470 }
@@ -546,10 +474,8 @@
546 474 *
547 475 * @param bool $exclude
548 476 * @param array $values
549 477 * @param array $errors By reference.
550 - *
551 - * @return void
552 478 */
553 479 public static function spam_check( $exclude, $values, &$errors ) {
554 480 if ( defined( 'WP_IMPORTING' ) && WP_IMPORTING ) {
555 481 // Do not check spam on importing.
@@ -562,9 +488,8 @@
562 488 }
563 489
564 490 $antispam_check = self::is_antispam_check( $values['form_id'] );
565 491 $spam_msg = FrmAntiSpamController::get_default_spam_message();
566 -
567 492 if ( is_string( $antispam_check ) ) {
568 493 $errors['spam'] = $antispam_check;
569 494 } elseif ( self::is_honeypot_spam( $values ) || self::is_spam_bot() ) {
570 495 $errors['spam'] = $spam_msg;
@@ -569,9 +494,8 @@
569 494 } elseif ( self::is_honeypot_spam( $values ) || self::is_spam_bot() ) {
570 495 $errors['spam'] = $spam_msg;
571 496 } else {
572 497 $is_spam = FrmAntiSpamController::is_spam( $values );
573 -
574 498 if ( $is_spam ) {
575 499 $errors['spam'] = $is_spam;
576 500 }
577 501 }
@@ -590,9 +514,8 @@
590 514 *
591 515 * @since 5.0.13
592 516 *
593 517 * @param array $values The values.
594 - *
595 518 * @return bool
596 519 */
597 520 private static function form_is_in_progress( $values ) {
598 521 return FrmAppHelper::pro_is_installed() &&
@@ -611,9 +534,8 @@
611 534 }
612 535
613 536 /**
614 537 * @param array $values
615 - *
616 538 * @return bool
617 539 */
618 540 private static function is_honeypot_spam( $values ) {
619 541 $honeypot = new FrmHoneypot( $values['form_id'] );
@@ -630,9 +552,8 @@
630 552 }
631 553
632 554 /**
633 555 * @param array $values
634 - *
635 556 * @return bool
636 557 */
637 558 private static function is_akismet_spam( $values ) {
638 559 global $wpcom_api_key;
@@ -641,9 +562,8 @@
641 562 }
642 563
643 564 /**
644 565 * @param int $form_id
645 - *
646 566 * @return bool
647 567 */
648 568 private static function is_akismet_enabled_for_user( $form_id ) {
649 569 $form = FrmForm::getOne( $form_id );
@@ -664,10 +584,8 @@
664 584
665 585 /**
666 586 * Check entries for Akismet spam
667 587 *
668 - * @param array $values Entry values.
669 - *
670 588 * @return bool true if is spam
671 589 */
672 590 public static function akismet( $values ) {
673 591 if ( empty( $values['item_meta'] ) ) {
@@ -695,13 +613,8 @@
695 613 }
696 614
697 615 /**
698 616 * @since 2.0
699 - *
700 - * @param array $datas The array of values being sent to Akismet.
701 - * @param array $values Entry values.
702 - *
703 - * @return void
704 617 */
705 618 private static function parse_akismet_array( &$datas, $values ) {
706 619 self::add_site_info_to_akismet( $datas );
707 620 self::add_server_values_to_akismet( $datas );
@@ -712,13 +625,8 @@
712 625 self::add_user_info_to_akismet( $datas, $values );
713 626 self::add_comment_content_to_akismet( $datas, $values );
714 627 }
715 628
716 - /**
717 - * @param array $datas
718 - *
719 - * @return void
720 - */
721 629 private static function add_site_info_to_akismet( &$datas ) {
722 630 $datas['blog'] = FrmAppHelper::site_url();
723 631 $datas['user_ip'] = preg_replace( '/[^0-9., ]/', '', FrmAppHelper::get_ip_address() );
724 632 $datas['user_agent'] = FrmAppHelper::get_server_value( 'HTTP_USER_AGENT' );
@@ -730,14 +638,8 @@
730 638 $datas['is_test'] = 'true';
731 639 }
732 640 }
733 641
734 - /**
735 - * @param array $datas
736 - * @param array $values
737 - *
738 - * @return void
739 - */
740 642 private static function add_user_info_to_akismet( &$datas, $values ) {
741 643 $user_info = self::get_spam_check_user_info( $values );
742 644 $datas = $datas + $user_info;
743 645
@@ -752,9 +654,8 @@
752 654 * @since 5.0.13 Separate code for guest. Handle value of embedded|repeater.
753 655 * @since 6.21 This changed from private to public.
754 656 *
755 657 * @param array $values Entry values after running through {@see FrmEntryValidate::prepare_values_for_spam_check()}.
756 - *
757 658 * @return array
758 659 */
759 660 public static function get_spam_check_user_info( $values ) {
760 661 if ( ! is_user_logged_in() ) {
@@ -777,9 +678,8 @@
777 678 *
778 679 * @since 5.0.13
779 680 *
780 681 * @param array $values Entry values after flattened.
781 - *
782 682 * @return array
783 683 */
784 684 private static function get_spam_check_user_info_for_guest( $values ) {
785 685 $datas = array(
@@ -811,10 +711,8 @@
811 711 *
812 712 * @param array $datas Guest data.
813 713 * @param array $values The values.
814 714 * @param int|null $custom_index Custom index (or field ID).
815 - *
816 - * @return void
817 715 */
818 716 private static function recursive_add_akismet_guest_info( &$datas, $values, $custom_index = null ) {
819 717 foreach ( $values as $index => $value ) {
820 718 if ( ! $datas['missing_keys'] ) {
@@ -827,12 +725,10 @@
827 725 continue;
828 726 }
829 727
830 728 $field_id = ! is_null( $custom_index ) ? $custom_index : $index;
831 -
832 729 foreach ( $datas['missing_keys'] as $key_index => $key ) {
833 730 $found = self::is_akismet_guest_info_value( $key, $value, $field_id, $datas['name_field_ids'], $values );
834 -
835 731 if ( $found ) {
836 732 $datas[ $key ] = $value;
837 733 $datas['frm_duplicated'][] = $field_id;
838 734 unset( $datas['missing_keys'][ $key_index ] );
@@ -870,9 +766,8 @@
870 766 if ( $name_field_ids && in_array( $field_id, $name_field_ids, true ) ) {
871 767 // If there is name field in the form, we should always use it as author name.
872 768 return true;
873 769 }
874 -
875 770 $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
876 771 $fields = self::get_name_text_fields( $form_id );
877 772
878 773 foreach ( $fields as $index => $field ) {
@@ -878,14 +773,12 @@
878 773 foreach ( $fields as $index => $field ) {
879 774 if ( 'Name' !== $field->name ) {
880 775 continue;
881 776 }
882 -
883 777 if ( isset( $fields[ $index + 1 ] ) && 'Last' === $fields[ $index + 1 ]->name ) {
884 778 if ( empty( $values[ absint( $fields[ $index + 1 ]->id ) ] ) ) {
885 779 continue;
886 780 }
887 -
888 781 $value .= ' ' . $values[ $fields[ $index + 1 ]->id ];
889 782 return true;
890 783 }
891 784 }
@@ -899,18 +792,15 @@
899 792 *
900 793 * @since 6.17
901 794 *
902 795 * @param int $form_id
903 - *
904 796 * @return array
905 797 */
906 798 private static function get_name_text_fields( $form_id ) {
907 799 $name_text_fields_is_initialized = is_array( self::$name_text_fields );
908 -
909 800 if ( $name_text_fields_is_initialized && isset( self::$name_text_fields[ $form_id ] ) ) {
910 801 return self::$name_text_fields[ $form_id ];
911 802 }
912 -
913 803 if ( ! $name_text_fields_is_initialized ) {
914 804 self::$name_text_fields = array();
915 805 }
916 806 self::$name_text_fields[ $form_id ] = FrmDb::get_results(
@@ -926,13 +816,8 @@
926 816
927 817 return self::$name_text_fields[ $form_id ];
928 818 }
929 819
930 - /**
931 - * @param array $datas
932 - *
933 - * @return void
934 - */
935 820 private static function add_server_values_to_akismet( &$datas ) {
936 821 foreach ( $_SERVER as $key => $value ) {
937 822 $include_value = is_string( $value ) && ! preg_match( '/^HTTP_COOKIE/', $key ) && preg_match( '/^(HTTP_|REMOTE_ADDR|REQUEST_URI|DOCUMENT_URI)/', $key );
938 823
@@ -950,10 +835,8 @@
950 835 * @since 5.0.09
951 836 *
952 837 * @param array $datas The array of values being sent to Akismet.
953 838 * @param array $values Entry values.
954 - *
955 - * @return void
956 839 */
957 840 private static function add_comment_content_to_akismet( &$datas, $values ) {
958 841 if ( isset( $datas['frm_duplicated'] ) ) {
959 842 foreach ( $datas['frm_duplicated'] as $index ) {
@@ -974,14 +857,11 @@
974 857 *
975 858 * @since 5.0.09
976 859 *
977 860 * @param array $values Entry values.
978 - *
979 - * @return void
980 861 */
981 862 private static function skip_adding_values_to_akismet( &$values ) {
982 863 $skipped_fields = self::get_akismet_skipped_field_ids( $values );
983 -
984 864 foreach ( $skipped_fields as $skipped_field ) {
985 865 if ( ! isset( $values['item_meta'][ $skipped_field->id ] ) ) {
986 866 continue;
987 867 }
@@ -987,9 +867,8 @@
987 867 }
988 868
989 869 if ( self::should_really_skip_field( $skipped_field, $values ) ) {
990 870 unset( $values['item_meta'][ $skipped_field->id ] );
991 -
992 871 if ( isset( $values['item_meta']['other'][ $skipped_field->id ] ) ) {
993 872 unset( $values['item_meta']['other'][ $skipped_field->id ] );
994 873 }
995 874 }
@@ -1002,9 +881,8 @@
1002 881 * @since 5.02.04
1003 882 *
1004 883 * @param object $field_data Object contains `id` and `options`.
1005 884 * @param array $values Entry values.
1006 - *
1007 885 * @return bool
1008 886 */
1009 887 private static function should_really_skip_field( $field_data, $values ) {
1010 888 if ( empty( $field_data->options ) ) {
@@ -1012,9 +890,8 @@
1012 890 return true;
1013 891 }
1014 892
1015 893 FrmAppHelper::unserialize_or_decode( $field_data->options );
1016 -
1017 894 if ( ! $field_data->options ) {
1018 895 // Check if an error happens when unserializing, or empty options.
1019 896 return true;
1020 897 }
@@ -1033,10 +910,9 @@
1033 910 }
1034 911
1035 912 // Check if submitted value is same as one of field option.
1036 913 foreach ( $field_data->options as $option ) {
1037 - $option_value = ! is_array( $option ) ? $option : ( $option['value'] ?? '' );
1038 -
914 + $option_value = ! is_array( $option ) ? $option : ( isset( $option['value'] ) ? $option['value'] : '' );
1039 915 if ( $values['item_meta']['other'][ $field_data->id ] === $option_value ) {
1040 916 return true;
1041 917 }
1042 918 }
@@ -1051,9 +927,8 @@
1051 927 * @since 5.0.13 Move out get_all_form_ids_and_flatten_meta() call and get `form_ids` from `$values`.
1052 928 * @since 5.2.04 This method returns array of object contains `id` and `options` instead of array of `id` only.
1053 929 *
1054 930 * @param array $values Entry values after running through {@see FrmEntryValidate::prepare_values_for_spam_check()}.
1055 - *
1056 931 * @return array
1057 932 */
1058 933 private static function get_akismet_skipped_field_ids( $values ) {
1059 934 if ( empty( $values['form_ids'] ) ) {
@@ -1079,10 +954,8 @@
1079 954 * @since 5.0.13
1080 955 * @since 6.21 This changed from private to public.
1081 956 *
1082 957 * @param array $values Entry values.
1083 - *
1084 - * @return void
1085 958 */
1086 959 public static function prepare_values_for_spam_check( &$values ) {
1087 960 $form_ids = self::get_all_form_ids_and_flatten_meta( $values );
1088 961 $values['form_ids'] = $form_ids;
@@ -1095,9 +968,8 @@
1095 968 * @since 5.0.09
1096 969 * @since 5.0.13 Convert name field value to string.
1097 970 *
1098 971 * @param array $values Entry values.
1099 - *
1100 972 * @return array Form IDs.
1101 973 */
1102 974 private static function get_all_form_ids_and_flatten_meta( &$values ) {
1103 975 $values['name_field_ids'] = array();
@@ -1103,9 +975,8 @@
1103 975 $values['name_field_ids'] = array();
1104 976
1105 977 // Blacklist check for File field in the old version doesn't contain `form_id`.
1106 978 $form_ids = isset( $values['form_id'] ) ? array( absint( $values['form_id'] ) ) : array();
1107 -
1108 979 foreach ( $values['item_meta'] as $field_id => $value ) {
1109 980 if ( ! is_numeric( $field_id ) ) {
1110 981 // Maybe `other`.
1111 982 continue;