PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.10
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.10
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 +54 -56 6.56.10 View file →
@@ -6,9 +6,9 @@
6 6 class FrmEntryValidate {
7 7
8 8 /**
9 9 * @param array $values
10 - * @param string[]|bool $exclude
10 + * @param bool|string[] $exclude
11 11 * @return array
12 12 */
13 13 public static function validate( $values, $exclude = false ) {
14 14 FrmEntry::sanitize_entry_post( $values );
@@ -24,8 +24,9 @@
24 24 $frm_settings = FrmAppHelper::get_settings();
25 25 $errors['form'] = $frm_settings->admin_permission;
26 26 }
27 27
28 + self::maybe_fix_item_meta();
28 29 self::set_item_key( $values );
29 30
30 31 $posted_fields = self::get_fields_to_validate( $values, $exclude );
31 32
@@ -60,8 +61,23 @@
60 61
61 62 return $errors;
62 63 }
63 64
65 + /**
66 + * In case $_POST['item_meta'] is not an array, change it to an empty array.
67 + * This helps to avoid some warnings and errors when $_POST['item_meta'] is updated.
68 + *
69 + * @since 6.6
70 + *
71 + * @return void
72 + */
73 + private static function maybe_fix_item_meta() {
74 + // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated
75 + if ( ! isset( $_POST['item_meta'] ) || ! is_array( $_POST['item_meta'] ) ) {
76 + $_POST['item_meta'] = array();
77 + }
78 + }
79 +
64 80 private static function set_item_key( &$values ) {
65 81 if ( ! isset( $values['item_key'] ) || $values['item_key'] == '' ) {
66 82 global $wpdb;
67 83 $values['item_key'] = FrmAppHelper::get_unique_key( '', $wpdb->prefix . 'frm_items', 'item_key' );
@@ -95,13 +111,17 @@
95 111
96 112 public static function validate_field( $posted_field, &$errors, $values, $args = array() ) {
97 113 $defaults = array(
98 114 'id' => $posted_field->id,
99 - 'parent_field_id' => '', // the id of the repeat or embed form
100 - 'key_pointer' => '', // the pointer in the posted array
101 - 'exclude' => array(), // exclude these field types from validation
115 + // The id of the repeat or embed form.
116 + 'parent_field_id' => '',
117 + // The pointer in the posted array.
118 + 'key_pointer' => '',
119 + // Exclude these field types from validation.
120 + 'exclude' => array(),
121 +
102 122 );
103 - $args = wp_parse_args( $args, $defaults );
123 + $args = wp_parse_args( $args, $defaults );
104 124
105 125 if ( empty( $args['parent_field_id'] ) ) {
106 126 $value = isset( $values['item_meta'][ $args['id'] ] ) ? $values['item_meta'][ $args['id'] ] : '';
107 127 } else {
@@ -142,8 +162,12 @@
142 162 }
143 163
144 164 $errors = apply_filters( 'frm_validate_' . $posted_field->type . '_field_entry', $errors, $posted_field, $value, $args );
145 165 $errors = apply_filters( 'frm_validate_field_entry', $errors, $posted_field, $value, $args );
166 +
167 + if ( ! FrmAppHelper::pro_is_installed() && empty( $args['other'] ) ) {
168 + FrmEntriesHelper::get_posted_value( $posted_field, $value, $args );
169 + }
146 170 }
147 171
148 172 /**
149 173 * Maybe add item_name to $_POST to save it in items table.
@@ -149,9 +173,10 @@
149 173 * Maybe add item_name to $_POST to save it in items table.
150 174 *
151 175 * @since 5.2.02
152 176 *
153 - * @param object $field Field object.
177 + * @param array|string $value Field value.
178 + * @param object $field Field object.
154 179 */
155 180 private static function maybe_add_item_name( $value, $field ) {
156 181 $item_name = false;
157 182 if ( 'name' === $field->type ) {
@@ -195,9 +220,9 @@
195 220 }
196 221 }
197 222
198 223 public static function validate_phone_field( &$errors, $field, $value, $args ) {
199 - if ( $field->type == 'phone' || ( $field->type == 'text' && FrmField::is_option_true_in_object( $field, 'format' ) ) ) {
224 + if ( $field->type === 'phone' || ( $field->type === 'text' && FrmField::is_option_true_in_object( $field, 'format' ) ) ) {
200 225
201 226 $pattern = self::phone_format( $field );
202 227
203 228 if ( ! preg_match( $pattern, $value ) ) {
@@ -272,14 +297,14 @@
272 297
273 298 /**
274 299 * Check for spam
275 300 *
276 - * @param boolean $exclude
301 + * @param bool $exclude
277 302 * @param array $values
278 - * @param array $errors by reference
303 + * @param array $errors By reference.
279 304 */
280 305 public static function spam_check( $exclude, $values, &$errors ) {
281 - if ( ! empty( $exclude ) || ! isset( $values['item_meta'] ) || empty( $values['item_meta'] ) || ! empty( $errors ) ) {
306 + if ( ! empty( $exclude ) || empty( $values['item_meta'] ) || ! empty( $errors ) ) {
282 307 // only check spam if there are no other errors
283 308 return;
284 309 }
285 310
@@ -326,9 +351,9 @@
326 351 }
327 352
328 353 /**
329 354 * @param array $values
330 - * @return boolean
355 + * @return bool
331 356 */
332 357 private static function is_honeypot_spam( $values ) {
333 358 $honeypot = new FrmHoneypot( $values['form_id'] );
334 359 return ! $honeypot->validate();
@@ -334,9 +359,9 @@
334 359 return ! $honeypot->validate();
335 360 }
336 361
337 362 /**
338 - * @return boolean
363 + * @return bool
339 364 */
340 365 private static function is_spam_bot() {
341 366 $ip = FrmAppHelper::get_ip_address();
342 367
@@ -344,9 +369,9 @@
344 369 }
345 370
346 371 /**
347 372 * @param array $values
348 - * @return boolean
373 + * @return bool
349 374 */
350 375 private static function is_akismet_spam( $values ) {
351 376 global $wpcom_api_key;
352 377
@@ -390,11 +415,11 @@
390 415 */
391 416 private static function check_disallowed_words( $author, $email, $url, $content, $ip, $user_agent ) {
392 417 if ( function_exists( 'wp_check_comment_disallowed_list' ) ) {
393 418 return wp_check_comment_disallowed_list( $author, $email, $url, $content, $ip, $user_agent );
394 - } else {
395 - return wp_blacklist_check( $author, $email, $url, $content, $ip, $user_agent );
396 419 }
420 + // phpcs:ignore WordPress.WP.DeprecatedFunctions.wp_blacklist_checkFound
421 + return wp_blacklist_check( $author, $email, $url, $content, $ip, $user_agent );
397 422 }
398 423
399 424 /**
400 425 * For WP 5.5 compatibility.
@@ -404,8 +429,9 @@
404 429 private static function get_disallowed_words() {
405 430 $keys = get_option( 'disallowed_keys' );
406 431 if ( false === $keys ) {
407 432 // Fallback for WP < 5.5.
433 + // phpcs:ignore WordPress.WP.DeprecatedParameterValues.Found
408 434 $keys = get_option( 'blacklist_keys' );
409 435 }
410 436 return $keys;
411 437 }
@@ -412,9 +438,9 @@
412 438
413 439 /**
414 440 * Check entries for Akismet spam
415 441 *
416 - * @return boolean true if is spam
442 + * @return bool true if is spam
417 443 */
418 444 public static function akismet( $values ) {
419 445 if ( empty( $values['item_meta'] ) ) {
420 446 return false;
@@ -436,9 +462,9 @@
436 462
437 463 $query_string = _http_build_query( $datas, '', '&' );
438 464 $response = Akismet::http_post( $query_string, 'comment-check' );
439 465
440 - return ( is_array( $response ) && $response[1] == 'true' );
466 + return ( is_array( $response ) && $response[1] === 'true' );
441 467 }
442 468
443 469 /**
444 470 * @since 2.0
@@ -541,9 +567,10 @@
541 567 */
542 568 private static function recursive_add_akismet_guest_info( &$datas, $values, $custom_index = null ) {
543 569 foreach ( $values as $index => $value ) {
544 570 if ( ! $datas['missing_keys'] ) {
545 - return; // Found all info.
571 + // Found all info.
572 + return;
546 573 }
547 574
548 575 if ( is_array( $value ) ) {
549 576 self::recursive_add_akismet_guest_info( $datas, $value, $index );
@@ -558,9 +585,9 @@
558 585 $datas['frm_duplicated'][] = $field_id;
559 586 unset( $datas['missing_keys'][ $key_index ] );
560 587 }
561 588 }
562 - }
589 + }//end foreach
563 590 }
564 591
565 592 /**
566 593 * Checks if given value is an akismet guest info.
@@ -665,14 +692,16 @@
665 692 * @param array $values Entry values.
666 693 * @return bool
667 694 */
668 695 private static function should_really_skip_field( $field_data, $values ) {
669 - if ( empty( $field_data->options ) ) { // This is skipped field types.
696 + if ( empty( $field_data->options ) ) {
697 + // This is skipped field types.
670 698 return true;
671 699 }
672 700
673 701 FrmAppHelper::unserialize_or_decode( $field_data->options );
674 - if ( ! $field_data->options ) { // Check if an error happens when unserializing, or empty options.
702 + if ( ! $field_data->options ) {
703 + // Check if an error happens when unserializing, or empty options.
675 704 return true;
676 705 }
677 706
678 707 end( $field_data->options );
@@ -754,9 +783,10 @@
754 783
755 784 // Blacklist check for File field in the old version doesn't contain `form_id`.
756 785 $form_ids = isset( $values['form_id'] ) ? array( absint( $values['form_id'] ) ) : array();
757 786 foreach ( $values['item_meta'] as $field_id => $value ) {
758 - if ( ! is_numeric( $field_id ) ) { // Maybe `other`.
787 + if ( ! is_numeric( $field_id ) ) {
788 + // Maybe `other`.
759 789 continue;
760 790 }
761 791
762 792 // Convert name array to string.
@@ -794,44 +824,12 @@
794 824 }
795 825
796 826 $values['item_meta'][ $subsubindex ][] = $subsubvalue;
797 827 }
798 - }
828 + }//end foreach
799 829
800 830 unset( $values['item_meta'][ $field_id ] );
801 - }
831 + }//end foreach
802 832
803 833 return $form_ids;
804 - }
805 -
806 - /**
807 - * @deprecated 3.0
808 - * @codeCoverageIgnore
809 - */
810 - public static function validate_url_field( &$errors, $field, $value, $args ) {
811 - FrmDeprecated::validate_url_field( $errors, $field, $value, $args );
812 - }
813 -
814 - /**
815 - * @deprecated 3.0
816 - * @codeCoverageIgnore
817 - */
818 - public static function validate_email_field( &$errors, $field, $value, $args ) {
819 - FrmDeprecated::validate_email_field( $errors, $field, $value, $args );
820 - }
821 -
822 - /**
823 - * @deprecated 3.0
824 - * @codeCoverageIgnore
825 - */
826 - public static function validate_number_field( &$errors, $field, $value, $args ) {
827 - FrmDeprecated::validate_number_field( $errors, $field, $value, $args );
828 - }
829 -
830 - /**
831 - * @deprecated 3.0
832 - * @codeCoverageIgnore
833 - */
834 - public static function validate_recaptcha( &$errors, $field, $args ) {
835 - FrmDeprecated::validate_recaptcha( $errors, $field, $args );
836 834 }
837 835 }