PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / trunk
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More vtrunk
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 +48 -35 6.27 → trunk View file →
@@ -90,13 +90,15 @@
90 90 * @return void
91 91 */
92 92 private static function set_item_key( &$values ) {
93 93 // phpcs:ignore Universal.Operators.StrictComparisons
94 - if ( ! isset( $values['item_key'] ) || $values['item_key'] == '' ) {
95 - global $wpdb;
96 - $values['item_key'] = FrmAppHelper::get_unique_key( '', $wpdb->prefix . 'frm_items', 'item_key' );
97 - $_POST['item_key'] = $values['item_key'];
94 + if ( isset( $values['item_key'] ) && $values['item_key'] != '' ) {
95 + return;
98 96 }
97 +
98 + global $wpdb;
99 + $values['item_key'] = FrmAppHelper::get_unique_key( '', $wpdb->prefix . 'frm_items', 'item_key' );
100 + $_POST['item_key'] = $values['item_key'];
99 101 }
100 102
101 103 /**
102 104 * @param array $values
@@ -147,9 +149,9 @@
147 149 'exclude' => array(),
148 150
149 151 );
150 152 $args = wp_parse_args( $args, $defaults );
151 - $value = empty( $args['parent_field_id'] ) ? ( $values['item_meta'][ $args['id'] ] ?? '' ) : $values;
153 + $value = ! empty( $args['parent_field_id'] ) ? $values : ( $values['item_meta'][ $args['id'] ] ?? '' );
152 154
153 155 // Check for values in "Other" fields
154 156 FrmEntriesHelper::maybe_set_other_validation( $posted_field, $value, $args );
155 157
@@ -277,8 +279,11 @@
277 279 } else {
278 280 $option_value = $option;
279 281 }
280 282
283 + /**
284 + * @var string $current_value
285 + */
281 286 $match = trim( $current_value ) === trim( $option_value );
282 287
283 288 if ( $match ) {
284 289 break;
@@ -295,14 +300,16 @@
295 300 if ( $match ) {
296 301 break;
297 302 }
298 303
299 - if ( is_numeric( $current_value ) ) {
300 - $match = (int) $current_value === (int) $option_value;
304 + if ( ! is_numeric( $current_value ) ) {
305 + continue;
306 + }
301 307
302 - if ( $match ) {
303 - break;
304 - }
308 + $match = (int) $current_value === (int) $option_value;
309 +
310 + if ( $match ) {
311 + break;
305 312 }
306 313 }//end foreach
307 314
308 315 if ( ! $match ) {
@@ -395,9 +402,9 @@
395 402 }
396 403
397 404 if ( false !== $item_name ) {
398 405 // Item name has a max length of 255 characters so truncate it so it doesn't fail to save in the database.
399 - $_POST['item_name'] = substr( $item_name, 0, 255 );
406 + $_POST['item_name'] = FrmAppHelper::truncate( $item_name, 255, 1, '', true );
400 407 }
401 408 }
402 409
403 410 /**
@@ -450,14 +457,16 @@
450 457 */
451 458 public static function validate_phone_field( &$errors, $field, $value, $args ) {
452 459 $format_value = FrmField::get_option( $field, 'format' );
453 460
454 - if ( $field->type === 'phone' || ( $field->type === 'text' && $format_value && ! FrmCurrencyHelper::is_currency_format( $format_value ) ) ) {
455 - $pattern = self::phone_format( $field );
461 + if ( $field->type !== 'phone' && ( $field->type !== 'text' || ! $format_value || FrmCurrencyHelper::is_currency_format( $format_value ) ) ) {
462 + return;
463 + }
456 464
457 - if ( ! preg_match( $pattern, $value ) ) {
458 - $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $field, 'invalid' );
459 - }
465 + $pattern = self::phone_format( $field );
466 +
467 + if ( ! preg_match( $pattern, $value ) ) {
468 + $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $field, 'invalid' );
460 469 }
461 470 }
462 471
463 472 /**
@@ -520,12 +529,12 @@
520 529 $parts = explode( '\?', $pattern );
521 530 $pattern = '';
522 531
523 532 foreach ( $parts as $part ) {
524 - if ( ! $pattern ) {
533 + if ( $pattern ) {
534 + $pattern .= '(' . $part . ')?';
535 + } else {
525 536 $pattern .= $part;
526 - } else {
527 - $pattern .= '(' . $part . ')?';
528 537 }
529 538 }
530 539 }
531 540
@@ -546,10 +555,10 @@
546 555 // Do not check spam on importing.
547 556 return;
548 557 }
549 558
550 - if ( $exclude || empty( $values['item_meta'] ) || ! empty( $errors ) ) {
551 - // only check spam if there are no other errors
559 + if ( $exclude || empty( $values['item_meta'] ) || $errors ) {
560 + // Only check spam if there are no other errors
552 561 return;
553 562 }
554 563
555 564 $antispam_check = self::is_antispam_check( $values['form_id'] );
@@ -585,11 +594,13 @@
585 594 *
586 595 * @return bool
587 596 */
588 597 private static function form_is_in_progress( $values ) {
598 + // phpcs:disable Generic.WhiteSpace.ScopeIndent
589 599 return FrmAppHelper::pro_is_installed() &&
590 600 ( isset( $values[ 'frm_page_order_' . $values['form_id'] ] ) || FrmAppHelper::get_post_param( 'frm_next_page' ) ) &&
591 601 FrmField::get_all_types_in_form( $values['form_id'], 'break' );
602 + // phpcs:enable Generic.WhiteSpace.ScopeIndent
592 603 }
593 604
594 605 /**
595 606 * @param int $form_id
@@ -614,10 +625,9 @@
614 625 /**
615 626 * @return bool
616 627 */
617 628 private static function is_spam_bot() {
618 - $ip = FrmAppHelper::get_ip_address();
619 - return empty( $ip );
629 + return ! FrmAppHelper::get_ip_address();
620 630 }
621 631
622 632 /**
623 633 * @param array $values
@@ -819,13 +829,15 @@
819 829
820 830 foreach ( $datas['missing_keys'] as $key_index => $key ) {
821 831 $found = self::is_akismet_guest_info_value( $key, $value, $field_id, $datas['name_field_ids'], $values );
822 832
823 - if ( $found ) {
824 - $datas[ $key ] = $value;
825 - $datas['frm_duplicated'][] = $field_id;
826 - unset( $datas['missing_keys'][ $key_index ] );
833 + if ( ! $found ) {
834 + continue;
827 835 }
836 +
837 + $datas[ $key ] = $value;
838 + $datas['frm_duplicated'][] = $field_id;
839 + unset( $datas['missing_keys'][ $key_index ] );
828 840 }
829 841 }//end foreach
830 842 }
831 843
@@ -973,14 +985,16 @@
973 985 if ( ! isset( $values['item_meta'][ $skipped_field->id ] ) ) {
974 986 continue;
975 987 }
976 988
977 - if ( self::should_really_skip_field( $skipped_field, $values ) ) {
978 - unset( $values['item_meta'][ $skipped_field->id ] );
989 + if ( ! self::should_really_skip_field( $skipped_field, $values ) ) {
990 + continue;
991 + }
979 992
980 - if ( isset( $values['item_meta']['other'][ $skipped_field->id ] ) ) {
981 - unset( $values['item_meta']['other'][ $skipped_field->id ] );
982 - }
993 + unset( $values['item_meta'][ $skipped_field->id ] );
994 +
995 + if ( isset( $values['item_meta']['other'][ $skipped_field->id ] ) ) {
996 + unset( $values['item_meta']['other'][ $skipped_field->id ] );
983 997 }
984 998 }
985 999 }
986 1000
@@ -1020,9 +1034,9 @@
1020 1034 }
1021 1035
1022 1036 // Check if submitted value is same as one of field option.
1023 1037 foreach ( $field_data->options as $option ) {
1024 - $option_value = ! is_array( $option ) ? $option : ( $option['value'] ?? '' );
1038 + $option_value = is_array( $option ) ? ( $option['value'] ?? '' ) : $option;
1025 1039
1026 1040 if ( $values['item_meta']['other'][ $field_data->id ] === $option_value ) {
1027 1041 return true;
1028 1042 }
@@ -1070,10 +1084,9 @@
1070 1084 *
1071 1085 * @return void
1072 1086 */
1073 1087 public static function prepare_values_for_spam_check( &$values ) {
1074 - $form_ids = self::get_all_form_ids_and_flatten_meta( $values );
1075 - $values['form_ids'] = $form_ids;
1088 + $values['form_ids'] = self::get_all_form_ids_and_flatten_meta( $values );
1076 1089 }
1077 1090
1078 1091 /**
1079 1092 * Gets all form IDs (include child form IDs) and flatten item_meta array. Used for skipping values sent to Akismet.