PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.2
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.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 +15 -41 6.276.2 View file →
@@ -14,11 +14,8 @@
14 14 *
15 15 * @return void
16 16 */
17 17 public static function ajax_create() {
18 - // This is called before we exit early to cover the conflict in Pro as well.
19 - self::fix_woocommerce_conflict();
20 -
21 18 if ( is_callable( 'FrmProEntriesController::ajax_create' ) ) {
22 19 // Let Pro handle AJAX Submit if it's available.
23 20 // This is because Pro requires additional code to support other Pro features.
24 21 return;
@@ -40,9 +37,8 @@
40 37 'pass' => false,
41 38 );
42 39
43 40 $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
44 -
45 41 if ( ! $form_id ) {
46 42 echo json_encode( $response );
47 43 wp_die();
48 44 }
@@ -47,9 +43,8 @@
47 43 wp_die();
48 44 }
49 45
50 46 $form = FrmForm::getOne( $form_id );
51 -
52 47 if ( ! $form ) {
53 48 echo json_encode( $response );
54 49 wp_die();
55 50 }
@@ -54,9 +49,8 @@
54 49 wp_die();
55 50 }
56 51
57 52 $is_ajax_on = FrmForm::is_ajax_on( $form );
58 -
59 53 if ( ! $is_ajax_on ) {
60 54 // This continues in the Pro version as it is required for other features including in-place edit.
61 55 // In Lite, if AJAX submit is not on, just exit early as this function is getting called incorrectly.
62 56 echo json_encode( $response );
@@ -79,9 +73,10 @@
79 73 // Trigger the footer scripts if there is a form to show.
80 74 if ( ! empty( $frm_vars['forms_loaded'] ) ) {
81 75 ob_start();
82 76 self::print_ajax_scripts();
83 - $response['content'] .= ob_get_clean();
77 + $response['content'] .= ob_get_contents();
78 + ob_end_clean();
84 79
85 80 // Mark the end of added footer content.
86 81 $response['content'] .= '<span class="frm_end_ajax_' . $form->id . '"></span>';
87 82 }
@@ -86,9 +81,8 @@
86 81 $response['content'] .= '<span class="frm_end_ajax_' . $form->id . '"></span>';
87 82 }
88 83 } else {
89 84 $obj = array();
90 -
91 85 foreach ( $errors as $field => $error ) {
92 86 $field_id = str_replace( 'field', '', $field );
93 87 $error = self::maybe_modify_ajax_error( $error, $field_id, $form, $errors );
94 88 $obj[ $field_id ] = $error;
@@ -103,9 +97,9 @@
103 97 'entry_id' => 0,
104 98 'class' => FrmFormsHelper::form_error_class(),
105 99 )
106 100 );
107 - }//end if
101 + }
108 102
109 103 $response = self::check_for_failed_form_submission( $response, $form->id );
110 104
111 105 echo json_encode( $response );
@@ -112,33 +106,8 @@
112 106 wp_die();
113 107 }
114 108
115 109 /**
116 - * Prevent WooCommerce 7.6.0 from triggering a fatal error when wp_print_footer_scripts is called.
117 - *
118 - * @since 6.2.3
119 - *
120 - * @return void
121 - */
122 - private static function fix_woocommerce_conflict() {
123 - add_action(
124 - 'wp_print_footer_scripts',
125 - function () {
126 - if ( ! function_exists( 'get_current_screen' ) ) {
127 - require_once ABSPATH . 'wp-admin/includes/screen.php';
128 - }
129 -
130 - if ( ! class_exists( 'WP_Screen', false ) ) {
131 - require_once ABSPATH . 'wp-admin/includes/class-wp-screen.php';
132 - }
133 -
134 - FrmAppHelper::set_current_screen_and_hook_suffix();
135 - },
136 - 1
137 - );
138 - }
139 -
140 - /**
141 110 * Load CAPTCHA script after AJAX submit so subsequent form CAPTCHAs don't break.
142 111 *
143 112 * @since 6.2
144 113 *
@@ -162,17 +131,23 @@
162 131 * @param string $error
163 132 * @param string $field_id
164 133 * @param stdClass $form the form being submitted (not necessarily the field's form when embedded/repeated).
165 134 * @param array $errors all errors that were caught in this form submission, passed into the frm_before_replace_shortcodes filter for reference.
166 - *
167 135 * @return string
168 136 */
169 137 private static function maybe_modify_ajax_error( $error, $field_id, $form, $errors ) {
170 - if ( ! is_numeric( $field_id ) ) {
138 + if ( false !== strpos( $field_id, '-' ) ) {
139 + // repeated fields look like field_id-repeater_id-iteration, so pull the first value for the field id.
140 + list( $use_field_id ) = explode( '-', $field_id );
141 + } else {
142 + $use_field_id = $field_id;
143 + }
144 +
145 + if ( ! is_numeric( $use_field_id ) ) {
171 146 return $error;
172 147 }
173 148
174 - $use_field = FrmField::getOne( $field_id );
149 + $use_field = FrmField::getOne( $use_field_id );
175 150
176 151 if ( ! $use_field ) {
177 152 return $error;
178 153 }
@@ -181,9 +156,9 @@
181 156 $error_body = FrmFieldsController::pull_custom_error_body_from_custom_html( $form, $use_field, $errors );
182 157
183 158 if ( false !== $error_body ) {
184 159 $error = str_replace( '[error]', $error, $error_body );
185 - $error = str_replace( '[key]', $use_field['field_key'], $error );
160 + $error = str_replace( '[key]', $field_id, $error );
186 161 }
187 162
188 163 return $error;
189 164 }
@@ -194,16 +169,15 @@
194 169 *
195 170 * @since 6.2
196 171 *
197 172 * @param array $response
198 - * @param int|string $form_id
199 - *
173 + * @param string|int $form_id
200 174 * @return array
201 175 */
202 176 private static function check_for_failed_form_submission( $response, $form_id ) {
203 177 $frm_settings = FrmAppHelper::get_settings( array( 'current_form' => $form_id ) );
204 178
205 - if ( str_contains( $response['content'], $frm_settings->failed_msg ) ) {
179 + if ( false !== strpos( $response['content'], $frm_settings->failed_msg ) ) {
206 180 $response['errors']['failed'] = $frm_settings->failed_msg;
207 181 $response['content'] = '';
208 182 }
209 183