PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / trunk
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More vtrunk
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 +27 -24 6.25 → trunk View file →
@@ -40,8 +40,9 @@
40 40 'pass' => false,
41 41 );
42 42
43 43 $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
44 +
44 45 if ( ! $form_id ) {
45 46 echo json_encode( $response );
46 47 wp_die();
47 48 }
@@ -46,15 +47,15 @@
46 47 wp_die();
47 48 }
48 49
49 50 $form = FrmForm::getOne( $form_id );
51 +
50 52 if ( ! $form ) {
51 53 echo json_encode( $response );
52 54 wp_die();
53 55 }
54 56
55 - $is_ajax_on = FrmForm::is_ajax_on( $form );
56 - if ( ! $is_ajax_on ) {
57 + if ( ! FrmForm::is_ajax_on( $form ) ) {
57 58 // This continues in the Pro version as it is required for other features including in-place edit.
58 59 // In Lite, if AJAX submit is not on, just exit early as this function is getting called incorrectly.
59 60 echo json_encode( $response );
60 61 wp_die();
@@ -61,9 +62,28 @@
61 62 }
62 63
63 64 $errors = FrmEntryValidate::validate( wp_unslash( $_POST ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
64 65
65 - 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 {
66 86 global $frm_vars;
67 87 $frm_vars['ajax'] = true;
68 88 $frm_vars['css_loaded'] = true;
69 89
@@ -76,32 +96,13 @@
76 96 // Trigger the footer scripts if there is a form to show.
77 97 if ( ! empty( $frm_vars['forms_loaded'] ) ) {
78 98 ob_start();
79 99 self::print_ajax_scripts();
80 - $response['content'] .= ob_get_contents();
81 - ob_end_clean();
100 + $response['content'] .= ob_get_clean();
82 101
83 102 // Mark the end of added footer content.
84 103 $response['content'] .= '<span class="frm_end_ajax_' . $form->id . '"></span>';
85 104 }
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 - );
104 105 }//end if
105 106
106 107 $response = self::check_for_failed_form_submission( $response, $form->id );
107 108
@@ -159,8 +160,9 @@
159 160 * @param string $error
160 161 * @param string $field_id
161 162 * @param stdClass $form the form being submitted (not necessarily the field's form when embedded/repeated).
162 163 * @param array $errors all errors that were caught in this form submission, passed into the frm_before_replace_shortcodes filter for reference.
164 + *
163 165 * @return string
164 166 */
165 167 private static function maybe_modify_ajax_error( $error, $field_id, $form, $errors ) {
166 168 if ( ! is_numeric( $field_id ) ) {
@@ -191,14 +193,15 @@
191 193 * @since 6.2
192 194 *
193 195 * @param array $response
194 196 * @param int|string $form_id
197 + *
195 198 * @return array
196 199 */
197 200 private static function check_for_failed_form_submission( $response, $form_id ) {
198 201 $frm_settings = FrmAppHelper::get_settings( array( 'current_form' => $form_id ) );
199 202
200 - if ( false !== strpos( $response['content'], $frm_settings->failed_msg ) ) {
203 + if ( str_contains( $response['content'], $frm_settings->failed_msg ) ) {
201 204 $response['errors']['failed'] = $frm_settings->failed_msg;
202 205 $response['content'] = '';
203 206 }
204 207