PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.7.2
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.7.2
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/controllers/FrmEntriesAJAXSubmitController.php +36 -32 6.32.16.7.2 View file →
@@ -40,9 +40,8 @@
40 40 'pass' => false,
41 41 );
42 42
43 43 $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
44 -
45 44 if ( ! $form_id ) {
46 45 echo json_encode( $response );
47 46 wp_die();
48 47 }
@@ -47,15 +46,15 @@
47 46 wp_die();
48 47 }
49 48
50 49 $form = FrmForm::getOne( $form_id );
51 -
52 50 if ( ! $form ) {
53 51 echo json_encode( $response );
54 52 wp_die();
55 53 }
56 54
57 - if ( ! FrmForm::is_ajax_on( $form ) ) {
55 + $is_ajax_on = FrmForm::is_ajax_on( $form );
56 + if ( ! $is_ajax_on ) {
58 57 // This continues in the Pro version as it is required for other features including in-place edit.
59 58 // In Lite, if AJAX submit is not on, just exit early as this function is getting called incorrectly.
60 59 echo json_encode( $response );
61 60 wp_die();
@@ -62,28 +61,9 @@
62 61 }
63 62
64 63 $errors = FrmEntryValidate::validate( wp_unslash( $_POST ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
65 64
66 - if ( $errors ) {
67 - $obj = array();
68 -
69 - foreach ( $errors as $field => $error ) {
70 - $field_id = str_replace( 'field', '', $field );
71 - $error = self::maybe_modify_ajax_error( $error, $field_id, $form, $errors );
72 - $obj[ $field_id ] = $error;
73 - }
74 -
75 - $response['errors'] = $obj;
76 - $invalid_msg = FrmFormsHelper::get_invalid_error_message( array( 'form' => $form ) );
77 - $response['error_message'] = FrmFormsHelper::get_success_message(
78 - array(
79 - 'message' => $invalid_msg,
80 - 'form' => $form,
81 - 'entry_id' => 0,
82 - 'class' => FrmFormsHelper::form_error_class(),
83 - )
84 - );
85 - } else {
65 + if ( ! $errors ) {
86 66 global $frm_vars;
87 67 $frm_vars['ajax'] = true;
88 68 $frm_vars['css_loaded'] = true;
89 69
@@ -96,13 +76,32 @@
96 76 // Trigger the footer scripts if there is a form to show.
97 77 if ( ! empty( $frm_vars['forms_loaded'] ) ) {
98 78 ob_start();
99 79 self::print_ajax_scripts();
100 - $response['content'] .= ob_get_clean();
80 + $response['content'] .= ob_get_contents();
81 + ob_end_clean();
101 82
102 83 // Mark the end of added footer content.
103 84 $response['content'] .= '<span class="frm_end_ajax_' . $form->id . '"></span>';
104 85 }
86 + } else {
87 + $obj = array();
88 + foreach ( $errors as $field => $error ) {
89 + $field_id = str_replace( 'field', '', $field );
90 + $error = self::maybe_modify_ajax_error( $error, $field_id, $form, $errors );
91 + $obj[ $field_id ] = $error;
92 + }
93 +
94 + $response['errors'] = $obj;
95 + $invalid_msg = FrmFormsHelper::get_invalid_error_message( array( 'form' => $form ) );
96 + $response['error_message'] = FrmFormsHelper::get_success_message(
97 + array(
98 + 'message' => $invalid_msg,
99 + 'form' => $form,
100 + 'entry_id' => 0,
101 + 'class' => FrmFormsHelper::form_error_class(),
102 + )
103 + );
105 104 }//end if
106 105
107 106 $response = self::check_for_failed_form_submission( $response, $form->id );
108 107
@@ -119,9 +118,9 @@
119 118 */
120 119 private static function fix_woocommerce_conflict() {
121 120 add_action(
122 121 'wp_print_footer_scripts',
123 - function () {
122 + function() {
124 123 if ( ! function_exists( 'get_current_screen' ) ) {
125 124 require_once ABSPATH . 'wp-admin/includes/screen.php';
126 125 }
127 126
@@ -160,17 +159,23 @@
160 159 * @param string $error
161 160 * @param string $field_id
162 161 * @param stdClass $form the form being submitted (not necessarily the field's form when embedded/repeated).
163 162 * @param array $errors all errors that were caught in this form submission, passed into the frm_before_replace_shortcodes filter for reference.
164 - *
165 163 * @return string
166 164 */
167 165 private static function maybe_modify_ajax_error( $error, $field_id, $form, $errors ) {
168 - if ( ! is_numeric( $field_id ) ) {
166 + if ( false !== strpos( $field_id, '-' ) ) {
167 + // repeated fields look like field_id-repeater_id-iteration, so pull the first value for the field id.
168 + list( $use_field_id ) = explode( '-', $field_id );
169 + } else {
170 + $use_field_id = $field_id;
171 + }
172 +
173 + if ( ! is_numeric( $use_field_id ) ) {
169 174 return $error;
170 175 }
171 176
172 - $use_field = FrmField::getOne( $field_id );
177 + $use_field = FrmField::getOne( $use_field_id );
173 178
174 179 if ( ! $use_field ) {
175 180 return $error;
176 181 }
@@ -179,9 +184,9 @@
179 184 $error_body = FrmFieldsController::pull_custom_error_body_from_custom_html( $form, $use_field, $errors );
180 185
181 186 if ( false !== $error_body ) {
182 187 $error = str_replace( '[error]', $error, $error_body );
183 - $error = str_replace( '[key]', $use_field['field_key'], $error );
188 + $error = str_replace( '[key]', $field_id, $error );
184 189 }
185 190
186 191 return $error;
187 192 }
@@ -192,16 +197,15 @@
192 197 *
193 198 * @since 6.2
194 199 *
195 200 * @param array $response
196 - * @param int|string $form_id
197 - *
201 + * @param string|int $form_id
198 202 * @return array
199 203 */
200 204 private static function check_for_failed_form_submission( $response, $form_id ) {
201 205 $frm_settings = FrmAppHelper::get_settings( array( 'current_form' => $form_id ) );
202 206
203 - if ( str_contains( $response['content'], $frm_settings->failed_msg ) ) {
207 + if ( false !== strpos( $response['content'], $frm_settings->failed_msg ) ) {
204 208 $response['errors']['failed'] = $frm_settings->failed_msg;
205 209 $response['content'] = '';
206 210 }
207 211