← All changes
|
classes/controllers/FrmEntriesAJAXSubmitController.php
+21
-23
6.27
→
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 | |
| @@ -84,27 +101,8 @@ | ||
| 84 | 101 | |
| 85 | 102 | // Mark the end of added footer content. |
| 86 | 103 | $response['content'] .= '<span class="frm_end_ajax_' . $form->id . '"></span>'; |
| 87 | 104 | } |
| 88 | - } else { | |
| 89 | - $obj = array(); | |
| 90 | - | |
| 91 | - foreach ( $errors as $field => $error ) { | |
| 92 | - $field_id = str_replace( 'field', '', $field ); | |
| 93 | - $error = self::maybe_modify_ajax_error( $error, $field_id, $form, $errors ); | |
| 94 | - $obj[ $field_id ] = $error; | |
| 95 | - } | |
| 96 | - | |
| 97 | - $response['errors'] = $obj; | |
| 98 | - $invalid_msg = FrmFormsHelper::get_invalid_error_message( array( 'form' => $form ) ); | |
| 99 | - $response['error_message'] = FrmFormsHelper::get_success_message( | |
| 100 | - array( | |
| 101 | - 'message' => $invalid_msg, | |
| 102 | - 'form' => $form, | |
| 103 | - 'entry_id' => 0, | |
| 104 | - 'class' => FrmFormsHelper::form_error_class(), | |
| 105 | - ) | |
| 106 | - ); | |
| 107 | 105 | }//end if |
| 108 | 106 | |
| 109 | 107 | $response = self::check_for_failed_form_submission( $response, $form->id ); |
| 110 | 108 | |