PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.1
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.1
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 +21 -98 6.55.1 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
@@ -20,10 +14,9 @@
20 14 return $errors;
21 15 }
22 16
23 17 if ( FrmAppHelper::is_admin() && is_user_logged_in() && ( ! isset( $values[ 'frm_submit_entry_' . $values['form_id'] ] ) || ! wp_verify_nonce( $values[ 'frm_submit_entry_' . $values['form_id'] ], 'frm_submit_entry_nonce' ) ) ) {
24 - $frm_settings = FrmAppHelper::get_settings();
25 - $errors['form'] = $frm_settings->admin_permission;
18 + $errors['form'] = __( 'You do not have permission to do that', 'formidable' );
26 19 }
27 20
28 21 self::set_item_key( $values );
29 22
@@ -49,16 +42,10 @@
49 42 * @param array $errors Errors data.
50 43 * @param array $values Value data of the form.
51 44 * @param array $args Custom arguments. Contains `exclude` and `posted_fields`.
52 45 */
53 - $filtered_errors = apply_filters( 'frm_validate_entry', $errors, $values, compact( 'exclude', 'posted_fields' ) );
46 + $errors = apply_filters( 'frm_validate_entry', $errors, $values, compact( 'exclude', 'posted_fields' ) );
54 47
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 48 return $errors;
62 49 }
63 50
64 51 private static function set_item_key( &$values ) {
@@ -124,10 +111,10 @@
124 111 }
125 112
126 113 if ( $posted_field->required == '1' && FrmAppHelper::is_empty_value( $value ) ) {
127 114 $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $posted_field, 'blank' );
128 - } elseif ( ! isset( $_POST['item_name'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
129 - self::maybe_add_item_name( $value, $posted_field );
115 + } elseif ( $posted_field->type === 'text' && ! isset( $_POST['item_name'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
116 + $_POST['item_name'] = $value;
130 117 }
131 118
132 119 FrmEntriesHelper::set_posted_value( $posted_field, $value, $args );
133 120
@@ -145,30 +132,8 @@
145 132 $errors = apply_filters( 'frm_validate_field_entry', $errors, $posted_field, $value, $args );
146 133 }
147 134
148 135 /**
149 - * Maybe add item_name to $_POST to save it in items table.
150 - *
151 - * @since 5.2.02
152 - *
153 - * @param object $field Field object.
154 - */
155 - private static function maybe_add_item_name( $value, $field ) {
156 - $item_name = false;
157 - if ( 'name' === $field->type ) {
158 - $field_obj = FrmFieldFactory::get_field_object( $field );
159 - $item_name = $field_obj->get_display_value( $value );
160 - } elseif ( 'text' === $field->type ) {
161 - $item_name = $value;
162 - }
163 -
164 - 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 );
167 - }
168 - }
169 -
170 - /**
171 136 * Set $value to an empty string if it matches its label
172 137 *
173 138 * @param object $field
174 139 * @param string $value
@@ -316,10 +281,9 @@
316 281 }
317 282
318 283 /**
319 284 * @param int $form_id
320 - *
321 - * @return bool|string
285 + * @return boolean
322 286 */
323 287 private static function is_antispam_check( $form_id ) {
324 288 $aspm = new FrmAntiSpam( $form_id );
325 289 return $aspm->validate();
@@ -373,8 +337,11 @@
373 337 return false;
374 338 }
375 339
376 340 $content = FrmEntriesHelper::entry_array_to_string( $values );
341 + if ( empty( $content ) ) {
342 + return false;
343 + }
377 344
378 345 self::prepare_values_for_spam_check( $values );
379 346 $ip = FrmAppHelper::get_ip_address();
380 347 $user_agent = FrmAppHelper::get_server_value( 'HTTP_USER_AGENT' );
@@ -640,72 +607,21 @@
640 607 *
641 608 * @param array $values Entry values.
642 609 */
643 610 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;
611 + $skipped_field_ids = self::get_akismet_skipped_field_ids( $values );
612 + foreach ( $skipped_field_ids as $field_id ) {
613 + if ( isset( $values['item_meta'][ $field_id ] ) ) {
614 + unset( $values['item_meta'][ $field_id ] );
648 615 }
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 616 }
657 617 }
658 618
659 619 /**
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 620 * Gets field IDs that are skipped from sending to Akismet spam check.
704 621 *
705 622 * @since 5.0.09
706 623 * @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 624 *
709 625 * @param array $values Entry values after running through {@see FrmEntryValidate::prepare_values_for_spam_check()}.
710 626 * @return array
711 627 */
@@ -719,13 +635,20 @@
719 635
720 636 $where = array(
721 637 array(
722 638 'form_id' => $values['form_ids'],
723 - 'type' => array_merge( $skipped_types, $has_other_types ),
639 + array(
640 + array(
641 + 'field_options not like' => ';s:5:"other";s:1:"1"',
642 + 'type' => $has_other_types,
643 + ),
644 + 'or' => 1,
645 + 'type' => $skipped_types,
646 + ),
724 647 ),
725 648 );
726 649
727 - return FrmDb::get_results( 'frm_fields', $where, 'id,options' );
650 + return FrmDb::get_col( 'frm_fields', $where );
728 651 }
729 652
730 653 /**
731 654 * Prepares values array for spam check.