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