PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.21
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.21
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 +22 -27 6.296.21 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 );
@@ -64,28 +61,9 @@
64 61 }
65 62
66 63 $errors = FrmEntryValidate::validate( wp_unslash( $_POST ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
67 64
68 - if ( $errors ) {
69 - $obj = array();
70 -
71 - foreach ( $errors as $field => $error ) {
72 - $field_id = str_replace( 'field', '', $field );
73 - $error = self::maybe_modify_ajax_error( $error, $field_id, $form, $errors );
74 - $obj[ $field_id ] = $error;
75 - }
76 -
77 - $response['errors'] = $obj;
78 - $invalid_msg = FrmFormsHelper::get_invalid_error_message( array( 'form' => $form ) );
79 - $response['error_message'] = FrmFormsHelper::get_success_message(
80 - array(
81 - 'message' => $invalid_msg,
82 - 'form' => $form,
83 - 'entry_id' => 0,
84 - 'class' => FrmFormsHelper::form_error_class(),
85 - )
86 - );
87 - } else {
65 + if ( ! $errors ) {
88 66 global $frm_vars;
89 67 $frm_vars['ajax'] = true;
90 68 $frm_vars['css_loaded'] = true;
91 69
@@ -98,13 +76,32 @@
98 76 // Trigger the footer scripts if there is a form to show.
99 77 if ( ! empty( $frm_vars['forms_loaded'] ) ) {
100 78 ob_start();
101 79 self::print_ajax_scripts();
102 - $response['content'] .= ob_get_clean();
80 + $response['content'] .= ob_get_contents();
81 + ob_end_clean();
103 82
104 83 // Mark the end of added footer content.
105 84 $response['content'] .= '<span class="frm_end_ajax_' . $form->id . '"></span>';
106 85 }
86 + } else {
87 + $obj = array();
88 + foreach ( $errors as $field => $error ) {
89 + $field_id = str_replace( 'field', '', $field );
90 + $error = self::maybe_modify_ajax_error( $error, $field_id, $form, $errors );
91 + $obj[ $field_id ] = $error;
92 + }
93 +
94 + $response['errors'] = $obj;
95 + $invalid_msg = FrmFormsHelper::get_invalid_error_message( array( 'form' => $form ) );
96 + $response['error_message'] = FrmFormsHelper::get_success_message(
97 + array(
98 + 'message' => $invalid_msg,
99 + 'form' => $form,
100 + 'entry_id' => 0,
101 + 'class' => FrmFormsHelper::form_error_class(),
102 + )
103 + );
107 104 }//end if
108 105
109 106 $response = self::check_for_failed_form_submission( $response, $form->id );
110 107
@@ -162,9 +159,8 @@
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 166 if ( ! is_numeric( $field_id ) ) {
@@ -195,15 +191,14 @@
195 191 * @since 6.2
196 192 *
197 193 * @param array $response
198 194 * @param int|string $form_id
199 - *
200 195 * @return array
201 196 */
202 197 private static function check_for_failed_form_submission( $response, $form_id ) {
203 198 $frm_settings = FrmAppHelper::get_settings( array( 'current_form' => $form_id ) );
204 199
205 - if ( str_contains( $response['content'], $frm_settings->failed_msg ) ) {
200 + if ( false !== strpos( $response['content'], $frm_settings->failed_msg ) ) {
206 201 $response['errors']['failed'] = $frm_settings->failed_msg;
207 202 $response['content'] = '';
208 203 }
209 204