← All changes
|
classes/controllers/FrmEntriesAJAXSubmitController.php
+15
-13
6.28
→
6.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,9 +46,8 @@ | ||
| 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 | } |
| @@ -54,9 +52,8 @@ | ||
| 54 | 52 | wp_die(); |
| 55 | 53 | } |
| 56 | 54 | |
| 57 | 55 | $is_ajax_on = FrmForm::is_ajax_on( $form ); |
| 58 | - | |
| 59 | 56 | if ( ! $is_ajax_on ) { |
| 60 | 57 | // This continues in the Pro version as it is required for other features including in-place edit. |
| 61 | 58 | // In Lite, if AJAX submit is not on, just exit early as this function is getting called incorrectly. |
| 62 | 59 | echo json_encode( $response ); |
| @@ -79,9 +76,10 @@ | ||
| 79 | 76 | // Trigger the footer scripts if there is a form to show. |
| 80 | 77 | if ( ! empty( $frm_vars['forms_loaded'] ) ) { |
| 81 | 78 | ob_start(); |
| 82 | 79 | self::print_ajax_scripts(); |
| 83 | - $response['content'] .= ob_get_clean(); | |
| 80 | + $response['content'] .= ob_get_contents(); | |
| 81 | + ob_end_clean(); | |
| 84 | 82 | |
| 85 | 83 | // Mark the end of added footer content. |
| 86 | 84 | $response['content'] .= '<span class="frm_end_ajax_' . $form->id . '"></span>'; |
| 87 | 85 | } |
| @@ -86,9 +84,8 @@ | ||
| 86 | 84 | $response['content'] .= '<span class="frm_end_ajax_' . $form->id . '"></span>'; |
| 87 | 85 | } |
| 88 | 86 | } else { |
| 89 | 87 | $obj = array(); |
| 90 | - | |
| 91 | 88 | foreach ( $errors as $field => $error ) { |
| 92 | 89 | $field_id = str_replace( 'field', '', $field ); |
| 93 | 90 | $error = self::maybe_modify_ajax_error( $error, $field_id, $form, $errors ); |
| 94 | 91 | $obj[ $field_id ] = $error; |
| @@ -121,9 +118,9 @@ | ||
| 121 | 118 | */ |
| 122 | 119 | private static function fix_woocommerce_conflict() { |
| 123 | 120 | add_action( |
| 124 | 121 | 'wp_print_footer_scripts', |
| 125 | - function () { | |
| 122 | + function() { | |
| 126 | 123 | if ( ! function_exists( 'get_current_screen' ) ) { |
| 127 | 124 | require_once ABSPATH . 'wp-admin/includes/screen.php'; |
| 128 | 125 | } |
| 129 | 126 | |
| @@ -162,17 +159,23 @@ | ||
| 162 | 159 | * @param string $error |
| 163 | 160 | * @param string $field_id |
| 164 | 161 | * @param stdClass $form the form being submitted (not necessarily the field's form when embedded/repeated). |
| 165 | 162 | * @param array $errors all errors that were caught in this form submission, passed into the frm_before_replace_shortcodes filter for reference. |
| 166 | - * | |
| 167 | 163 | * @return string |
| 168 | 164 | */ |
| 169 | 165 | private static function maybe_modify_ajax_error( $error, $field_id, $form, $errors ) { |
| 170 | - 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 ) ) { | |
| 171 | 174 | return $error; |
| 172 | 175 | } |
| 173 | 176 | |
| 174 | - $use_field = FrmField::getOne( $field_id ); | |
| 177 | + $use_field = FrmField::getOne( $use_field_id ); | |
| 175 | 178 | |
| 176 | 179 | if ( ! $use_field ) { |
| 177 | 180 | return $error; |
| 178 | 181 | } |
| @@ -181,9 +184,9 @@ | ||
| 181 | 184 | $error_body = FrmFieldsController::pull_custom_error_body_from_custom_html( $form, $use_field, $errors ); |
| 182 | 185 | |
| 183 | 186 | if ( false !== $error_body ) { |
| 184 | 187 | $error = str_replace( '[error]', $error, $error_body ); |
| 185 | - $error = str_replace( '[key]', $use_field['field_key'], $error ); | |
| 188 | + $error = str_replace( '[key]', $field_id, $error ); | |
| 186 | 189 | } |
| 187 | 190 | |
| 188 | 191 | return $error; |
| 189 | 192 | } |
| @@ -194,16 +197,15 @@ | ||
| 194 | 197 | * |
| 195 | 198 | * @since 6.2 |
| 196 | 199 | * |
| 197 | 200 | * @param array $response |
| 198 | - * @param int|string $form_id | |
| 199 | - * | |
| 201 | + * @param string|int $form_id | |
| 200 | 202 | * @return array |
| 201 | 203 | */ |
| 202 | 204 | private static function check_for_failed_form_submission( $response, $form_id ) { |
| 203 | 205 | $frm_settings = FrmAppHelper::get_settings( array( 'current_form' => $form_id ) ); |
| 204 | 206 | |
| 205 | - if ( str_contains( $response['content'], $frm_settings->failed_msg ) ) { | |
| 207 | + if ( false !== strpos( $response['content'], $frm_settings->failed_msg ) ) { | |
| 206 | 208 | $response['errors']['failed'] = $frm_settings->failed_msg; |
| 207 | 209 | $response['content'] = ''; |
| 208 | 210 | } |
| 209 | 211 | |