PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.2.02
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.2.02
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 +19 -74 6.55.2.02 View file →
@@ -3,14 +3,8 @@
3 3 die( 'You are not allowed to call this page directly.' );
4 4 }
5 5
6 6 class FrmEntryValidate {
7 -
8 - /**
9 - * @param array $values
10 - * @param string[]|bool $exclude
11 - * @return array
12 - */
13 7 public static function validate( $values, $exclude = false ) {
14 8 FrmEntry::sanitize_entry_post( $values );
15 9 $errors = array();
16 10
@@ -49,16 +43,10 @@
49 43 * @param array $errors Errors data.
50 44 * @param array $values Value data of the form.
51 45 * @param array $args Custom arguments. Contains `exclude` and `posted_fields`.
52 46 */
53 - $filtered_errors = apply_filters( 'frm_validate_entry', $errors, $values, compact( 'exclude', 'posted_fields' ) );
47 + $errors = apply_filters( 'frm_validate_entry', $errors, $values, compact( 'exclude', 'posted_fields' ) );
54 48
55 - if ( is_array( $filtered_errors ) ) {
56 - $errors = $filtered_errors;
57 - } else {
58 - _doing_it_wrong( __FUNCTION__, 'Only arrays should be returned when using the frm_validate_entry filter.', '6.3' );
59 - }
60 -
61 49 return $errors;
62 50 }
63 51
64 52 private static function set_item_key( &$values ) {
@@ -161,10 +149,9 @@
161 149 $item_name = $value;
162 150 }
163 151
164 152 if ( false !== $item_name ) {
165 - // Item name has a max length of 255 characters so truncate it so it doesn't fail to save in the database.
166 - $_POST['item_name'] = substr( $item_name, 0, 255 );
153 + $_POST['item_name'] = $item_name;
167 154 }
168 155 }
169 156
170 157 /**
@@ -316,10 +303,9 @@
316 303 }
317 304
318 305 /**
319 306 * @param int $form_id
320 - *
321 - * @return bool|string
307 + * @return boolean
322 308 */
323 309 private static function is_antispam_check( $form_id ) {
324 310 $aspm = new FrmAntiSpam( $form_id );
325 311 return $aspm->validate();
@@ -373,8 +359,11 @@
373 359 return false;
374 360 }
375 361
376 362 $content = FrmEntriesHelper::entry_array_to_string( $values );
363 + if ( empty( $content ) ) {
364 + return false;
365 + }
377 366
378 367 self::prepare_values_for_spam_check( $values );
379 368 $ip = FrmAppHelper::get_ip_address();
380 369 $user_agent = FrmAppHelper::get_server_value( 'HTTP_USER_AGENT' );
@@ -640,72 +629,21 @@
640 629 *
641 630 * @param array $values Entry values.
642 631 */
643 632 private static function skip_adding_values_to_akismet( &$values ) {
644 - $skipped_fields = self::get_akismet_skipped_field_ids( $values );
645 - foreach ( $skipped_fields as $skipped_field ) {
646 - if ( ! isset( $values['item_meta'][ $skipped_field->id ] ) ) {
647 - continue;
633 + $skipped_field_ids = self::get_akismet_skipped_field_ids( $values );
634 + foreach ( $skipped_field_ids as $field_id ) {
635 + if ( isset( $values['item_meta'][ $field_id ] ) ) {
636 + unset( $values['item_meta'][ $field_id ] );
648 637 }
649 -
650 - if ( self::should_really_skip_field( $skipped_field, $values ) ) {
651 - unset( $values['item_meta'][ $skipped_field->id ] );
652 - if ( isset( $values['item_meta']['other'][ $skipped_field->id ] ) ) {
653 - unset( $values['item_meta']['other'][ $skipped_field->id ] );
654 - }
655 - }
656 638 }
657 639 }
658 640
659 641 /**
660 - * Checks if a skip field should be really skipped.
661 - *
662 - * @since 5.02.04
663 - *
664 - * @param object $field_data Object contains `id` and `options`.
665 - * @param array $values Entry values.
666 - * @return bool
667 - */
668 - private static function should_really_skip_field( $field_data, $values ) {
669 - if ( empty( $field_data->options ) ) { // This is skipped field types.
670 - return true;
671 - }
672 -
673 - FrmAppHelper::unserialize_or_decode( $field_data->options );
674 - if ( ! $field_data->options ) { // Check if an error happens when unserializing, or empty options.
675 - return true;
676 - }
677 -
678 - end( $field_data->options );
679 - $last_key = key( $field_data->options );
680 -
681 - // If a choice field has no Other option.
682 - if ( is_numeric( $last_key ) || 0 !== strpos( $last_key, 'other_' ) ) {
683 - return true;
684 - }
685 -
686 - // If a choice field has Other option, but Other is not selected.
687 - if ( empty( $values['item_meta']['other'][ $field_data->id ] ) ) {
688 - return true;
689 - }
690 -
691 - // Check if submitted value is same as one of field option.
692 - foreach ( $field_data->options as $option ) {
693 - $option_value = ! is_array( $option ) ? $option : ( isset( $option['value'] ) ? $option['value'] : '' );
694 - if ( $values['item_meta']['other'][ $field_data->id ] === $option_value ) {
695 - return true;
696 - }
697 - }
698 -
699 - return false;
700 - }
701 -
702 - /**
703 642 * Gets field IDs that are skipped from sending to Akismet spam check.
704 643 *
705 644 * @since 5.0.09
706 645 * @since 5.0.13 Move out get_all_form_ids_and_flatten_meta() call and get `form_ids` from `$values`.
707 - * @since 5.2.04 This method returns array of object contains `id` and `options` instead of array of `id` only.
708 646 *
709 647 * @param array $values Entry values after running through {@see FrmEntryValidate::prepare_values_for_spam_check()}.
710 648 * @return array
711 649 */
@@ -719,13 +657,20 @@
719 657
720 658 $where = array(
721 659 array(
722 660 'form_id' => $values['form_ids'],
723 - 'type' => array_merge( $skipped_types, $has_other_types ),
661 + array(
662 + array(
663 + 'field_options not like' => ';s:5:"other";s:1:"1"',
664 + 'type' => $has_other_types,
665 + ),
666 + 'or' => 1,
667 + 'type' => $skipped_types,
668 + ),
724 669 ),
725 670 );
726 671
727 - return FrmDb::get_results( 'frm_fields', $where, 'id,options' );
672 + return FrmDb::get_col( 'frm_fields', $where );
728 673 }
729 674
730 675 /**
731 676 * Prepares values array for spam check.