← All changes
|
classes/controllers/FrmEntriesAJAXSubmitController.php
+23
-26
6.26
→
trunk
View file →
| @@ -53,11 +53,9 @@ | ||
| 53 | 53 | echo json_encode( $response ); |
| 54 | 54 | wp_die(); |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - $is_ajax_on = FrmForm::is_ajax_on( $form ); | |
| 58 | - | |
| 59 | - if ( ! $is_ajax_on ) { | |
| 57 | + if ( ! FrmForm::is_ajax_on( $form ) ) { | |
| 60 | 58 | // This continues in the Pro version as it is required for other features including in-place edit. |
| 61 | 59 | // In Lite, if AJAX submit is not on, just exit early as this function is getting called incorrectly. |
| 62 | 60 | echo json_encode( $response ); |
| 63 | 61 | wp_die(); |
| @@ -64,9 +62,28 @@ | ||
| 64 | 62 | } |
| 65 | 63 | |
| 66 | 64 | $errors = FrmEntryValidate::validate( wp_unslash( $_POST ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 67 | 65 | |
| 68 | - if ( ! $errors ) { | |
| 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 { | |
| 69 | 86 | global $frm_vars; |
| 70 | 87 | $frm_vars['ajax'] = true; |
| 71 | 88 | $frm_vars['css_loaded'] = true; |
| 72 | 89 | |
| @@ -79,33 +96,13 @@ | ||
| 79 | 96 | // Trigger the footer scripts if there is a form to show. |
| 80 | 97 | if ( ! empty( $frm_vars['forms_loaded'] ) ) { |
| 81 | 98 | ob_start(); |
| 82 | 99 | self::print_ajax_scripts(); |
| 83 | - $response['content'] .= ob_get_contents(); | |
| 84 | - ob_end_clean(); | |
| 100 | + $response['content'] .= ob_get_clean(); | |
| 85 | 101 | |
| 86 | 102 | // Mark the end of added footer content. |
| 87 | 103 | $response['content'] .= '<span class="frm_end_ajax_' . $form->id . '"></span>'; |
| 88 | 104 | } |
| 89 | - } else { | |
| 90 | - $obj = array(); | |
| 91 | - | |
| 92 | - foreach ( $errors as $field => $error ) { | |
| 93 | - $field_id = str_replace( 'field', '', $field ); | |
| 94 | - $error = self::maybe_modify_ajax_error( $error, $field_id, $form, $errors ); | |
| 95 | - $obj[ $field_id ] = $error; | |
| 96 | - } | |
| 97 | - | |
| 98 | - $response['errors'] = $obj; | |
| 99 | - $invalid_msg = FrmFormsHelper::get_invalid_error_message( array( 'form' => $form ) ); | |
| 100 | - $response['error_message'] = FrmFormsHelper::get_success_message( | |
| 101 | - array( | |
| 102 | - 'message' => $invalid_msg, | |
| 103 | - 'form' => $form, | |
| 104 | - 'entry_id' => 0, | |
| 105 | - 'class' => FrmFormsHelper::form_error_class(), | |
| 106 | - ) | |
| 107 | - ); | |
| 108 | 105 | }//end if |
| 109 | 106 | |
| 110 | 107 | $response = self::check_for_failed_form_submission( $response, $form->id ); |
| 111 | 108 | |
| @@ -202,9 +199,9 @@ | ||
| 202 | 199 | */ |
| 203 | 200 | private static function check_for_failed_form_submission( $response, $form_id ) { |
| 204 | 201 | $frm_settings = FrmAppHelper::get_settings( array( 'current_form' => $form_id ) ); |
| 205 | 202 | |
| 206 | - if ( false !== strpos( $response['content'], $frm_settings->failed_msg ) ) { | |
| 203 | + if ( str_contains( $response['content'], $frm_settings->failed_msg ) ) { | |
| 207 | 204 | $response['errors']['failed'] = $frm_settings->failed_msg; |
| 208 | 205 | $response['content'] = ''; |
| 209 | 206 | } |
| 210 | 207 | |