Skip to content

Commit 4f12590

Browse files
Payment issue 70 (#90)
* Update Class and Emogrifier Update * Fixes Transation Table Entry ID's and Updates Emogrifier. Fixes issue-70 * Adds weSerialize fix to the frontend for testing * Updated Spacing * Updated Spacing * Updated Spacing for comments and handle_frontend_submission function Co-authored-by: Elana Davis <[email protected]>
1 parent eb7509d commit 4f12590

File tree

2 files changed

+1099
-812
lines changed

2 files changed

+1099
-812
lines changed

includes/class-ajax.php

Lines changed: 51 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,6 @@ public function save_form() {
118118
$integrations = (array) json_decode( $post_data['integrations'] );
119119
}
120120

121-
// $form_fields = wp_unslash( $form_fields );
122-
// $notifications = wp_unslash( $notifications );
123-
124121
$form_fields = json_decode( $form_fields, true );
125122
$notifications = json_decode( $notifications, true );
126123
$data = [
@@ -756,21 +753,30 @@ public function handle_frontend_submission() {
756753

757754
$entry_fields = apply_filters( 'weforms_before_entry_submission', $entry_fields, $form, $form_settings, $form_fields );
758755

759-
$entry_id = weforms_insert_entry( [
760-
'form_id' => $form_id,
761-
], $entry_fields );
762-
756+
$entry_id = 1;
757+
$global_settings = weforms_get_settings();
758+
if ( empty( $global_settings['after_submission'] ) ) {
759+
$entry_id = weforms_insert_entry( [
760+
'form_id' => $form_id,
761+
], $entry_fields );
763762
if ( is_wp_error( $entry_id ) ) {
764763
wp_send_json( [
765764
'success' => false,
766765
'error' => $entry_id->get_error_message(),
767766
] );
768767
}
769-
768+
// Fire a hook for integration
769+
do_action( 'weforms_entry_submission', $entry_id, $form_id, $page_id, $form_settings );
770+
$notification = new WeForms_Notification( [
771+
'form_id' => $form_id,
772+
'page_id' => $page_id,
773+
'entry_id' => $entry_id,
774+
] );
775+
$notification->send_notifications();
776+
}
770777
// redirect URL
771778
$show_message = false;
772-
$redirect_to = false;
773-
779+
$redirect_to = false;
774780
if ( $form_settings['redirect_to'] == 'page' ) {
775781
$redirect_to = get_permalink( $form_settings['page_id'] );
776782
} elseif ( $form_settings['redirect_to'] == 'url' ) {
@@ -780,15 +786,9 @@ public function handle_frontend_submission() {
780786
} else {
781787
$show_message = true;
782788
}
783-
784-
// Fire a hook for integration
785-
do_action( 'weforms_entry_submission', $entry_id, $form_id, $page_id, $form_settings );
786-
787789
$field_search = $field_replace = [];
788-
789790
foreach ( $form_fields as $r_field ) {
790791
$field_search[] = '{' . $r_field['name'] . '}';
791-
792792
if ( $r_field['template'] == 'name_field' ) {
793793
$field_replace[] = implode( ' ', explode( '|', $entry_fields[ $r_field['name'] ] ) );
794794
} else if ( $r_field['template'] == 'address_field' ) {
@@ -798,66 +798,57 @@ public function handle_frontend_submission() {
798798
}
799799
}
800800
$message = str_replace( $field_search, $field_replace, $form_settings['message'] );
801-
802801
// send the response
803802
$response = apply_filters( 'weforms_entry_submission_response', [
804-
'success' => true,
805-
'redirect_to' => $redirect_to,
803+
'success' => true,
804+
'redirect_to' => $redirect_to,
806805
'show_message' => $show_message,
807-
'message' => $message,
808-
'data' => $_POST,
809-
'form_id' => $form_id,
810-
'entry_id' => $entry_id,
811-
] );
812-
813-
$notification = new WeForms_Notification( [
814-
'form_id' => $form_id,
815-
'page_id' => $page_id,
816-
'entry_id' => $entry_id,
806+
'message' => $message,
807+
'data' => $_POST,
808+
'form_id' => $form_id,
809+
'entry_id' => $entry_id,
810+
'entry_fields' =>$entry_fields,
817811
] );
818-
819-
$notification->send_notifications();
820-
821812
weforms_clear_buffer();
822813
wp_send_json( $response );
823-
}
824-
825-
function validate_reCaptchav3( $secret ) {
826-
check_ajax_referer( 'wpuf_form_add' );
814+
}
827815

828-
$post_data = wp_unslash($_POST);
829-
$token = $post_data['g-recaptcha-response'];
830-
$action = $post_data['g-action'];
831-
$google_captcha_url = esc_url( 'https://www.google.com/recaptcha/api/siteverify' );
832-
833-
$response = wp_remote_post( $google_captcha_url,
834-
array(
835-
'method' => 'POST',
836-
'body' => array(
837-
'secret' => $secret,
838-
'response' => $token
816+
function validate_reCaptchav3( $secret ) {
817+
check_ajax_referer( 'wpuf_form_add' );
818+
819+
$post_data = wp_unslash($_POST);
820+
$token = $post_data['g-recaptcha-response'];
821+
$action = $post_data['g-action'];
822+
$google_captcha_url = esc_url( 'https://www.google.com/recaptcha/api/siteverify' );
823+
824+
$response = wp_remote_post( $google_captcha_url,
825+
array(
826+
'method' => 'POST',
827+
'body' => array(
828+
'secret' => $secret,
829+
'response' => $token
830+
)
839831
)
840-
)
841-
);
832+
);
842833

843834

844-
if ( is_wp_error( $response ) ) {
845-
wp_send_json( [
846-
'success' => false,
847-
'error' => __( 'reCAPTCHA validation failed', 'weforms' ),
848-
] );
849-
} else {
850-
$api_response = json_decode( wp_remote_retrieve_body( $response ), true );
851-
if( $api_response["success"] == '1' && $api_response["action"] == $action ) {
852-
return true;
853-
} else {
835+
if ( is_wp_error( $response ) ) {
854836
wp_send_json( [
855837
'success' => false,
856838
'error' => __( 'reCAPTCHA validation failed', 'weforms' ),
857839
] );
840+
} else {
841+
$api_response = json_decode( wp_remote_retrieve_body( $response ), true );
842+
if( $api_response["success"] == '1' && $api_response["action"] == $action ) {
843+
return true;
844+
} else {
845+
wp_send_json( [
846+
'success' => false,
847+
'error' => __( 'reCAPTCHA validation failed', 'weforms' ),
848+
] );
849+
}
858850
}
859851
}
860-
}
861852
/**
862853
* reCaptcha Validation
863854
*

0 commit comments

Comments
 (0)