| @@ -117,8 +117,11 @@ | ||
| 117 | 117 | if ( isset( $post_data['integrations'] ) ) { |
| 118 | 118 | $integrations = (array) json_decode( $post_data['integrations'] ); |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | + // $form_fields = wp_unslash( $form_fields ); | |
| 122 | + // $notifications = wp_unslash( $notifications ); | |
| 123 | + | |
| 121 | 124 | $form_fields = json_decode( $form_fields, true ); |
| 122 | 125 | $notifications = json_decode( $notifications, true ); |
| 123 | 126 | $data = [ |
| 124 | 127 | 'form_id' => absint( $form_data['wpuf_form_id'] ), |
| @@ -131,14 +134,8 @@ | ||
| 131 | 134 | ]; |
| 132 | 135 | |
| 133 | 136 | $form_fields = weforms()->form->save( $data ); |
| 134 | 137 | |
| 135 | - // Update Old Entry meta_key if changed | |
| 136 | - $form_id = $form_data['wpuf_form_id']; | |
| 137 | - $form = weforms()->form->get( $form_id ); | |
| 138 | - | |
| 139 | - $form->maybe_update_entries( $form_fields ); | |
| 140 | - | |
| 141 | 138 | do_action( 'weforms_update_form', $form_data['wpuf_form_id'], $form_fields, $settings ); |
| 142 | 139 | |
| 143 | 140 | wp_send_json_success( [ 'form_fields' => $form_fields ] ); |
| 144 | 141 | } |
| @@ -758,14 +755,12 @@ | ||
| 758 | 755 | $this->validate_submission( $entry_fields, $form, $form_settings, $form_fields ); |
| 759 | 756 | |
| 760 | 757 | $entry_fields = apply_filters( 'weforms_before_entry_submission', $entry_fields, $form, $form_settings, $form_fields ); |
| 761 | 758 | |
| 762 | - $entry_id = 1; | |
| 763 | - $global_settings = weforms_get_settings(); | |
| 764 | - if ( empty( $global_settings['after_submission'] ) ) { | |
| 765 | - $entry_id = weforms_insert_entry( [ | |
| 766 | - 'form_id' => $form_id, | |
| 767 | - ], $entry_fields ); | |
| 759 | + $entry_id = weforms_insert_entry( [ | |
| 760 | + 'form_id' => $form_id, | |
| 761 | + ], $entry_fields ); | |
| 762 | + | |
| 768 | 763 | if ( is_wp_error( $entry_id ) ) { |
| 769 | 764 | wp_send_json( [ |
| 770 | 765 | 'success' => false, |
| 771 | 766 | 'error' => $entry_id->get_error_message(), |
| @@ -770,20 +765,13 @@ | ||
| 770 | 765 | 'success' => false, |
| 771 | 766 | 'error' => $entry_id->get_error_message(), |
| 772 | 767 | ] ); |
| 773 | 768 | } |
| 774 | - // Fire a hook for integration | |
| 775 | - do_action( 'weforms_entry_submission', $entry_id, $form_id, $page_id, $form_settings ); | |
| 776 | - $notification = new WeForms_Notification( [ | |
| 777 | - 'form_id' => $form_id, | |
| 778 | - 'page_id' => $page_id, | |
| 779 | - 'entry_id' => $entry_id, | |
| 780 | - ] ); | |
| 781 | - $notification->send_notifications(); | |
| 782 | - } | |
| 769 | + | |
| 783 | 770 | // redirect URL |
| 784 | 771 | $show_message = false; |
| 785 | - $redirect_to = false; | |
| 772 | + $redirect_to = false; | |
| 773 | + | |
| 786 | 774 | if ( $form_settings['redirect_to'] == 'page' ) { |
| 787 | 775 | $redirect_to = get_permalink( $form_settings['page_id'] ); |
| 788 | 776 | } elseif ( $form_settings['redirect_to'] == 'url' ) { |
| 789 | 777 | $redirect_to = $form_settings['url']; |
| @@ -791,11 +779,17 @@ | ||
| 791 | 779 | $show_message = true; |
| 792 | 780 | } else { |
| 793 | 781 | $show_message = true; |
| 794 | 782 | } |
| 783 | + | |
| 784 | + // Fire a hook for integration | |
| 785 | + do_action( 'weforms_entry_submission', $entry_id, $form_id, $page_id, $form_settings ); | |
| 786 | + | |
| 795 | 787 | $field_search = $field_replace = []; |
| 788 | + | |
| 796 | 789 | foreach ( $form_fields as $r_field ) { |
| 797 | 790 | $field_search[] = '{' . $r_field['name'] . '}'; |
| 791 | + | |
| 798 | 792 | if ( $r_field['template'] == 'name_field' ) { |
| 799 | 793 | $field_replace[] = implode( ' ', explode( '|', $entry_fields[ $r_field['name'] ] ) ); |
| 800 | 794 | } else if ( $r_field['template'] == 'address_field' ) { |
| 801 | 795 | $field_replace[] = implode( ', ', $entry_fields[ $r_field['name'] ] ); |
| @@ -803,59 +797,68 @@ | ||
| 803 | 797 | $field_replace[] = isset( $entry_fields[ $r_field['name'] ] ) ? $entry_fields[ $r_field['name'] ] : ''; |
| 804 | 798 | } |
| 805 | 799 | } |
| 806 | 800 | $message = str_replace( $field_search, $field_replace, $form_settings['message'] ); |
| 801 | + | |
| 807 | 802 | // send the response |
| 808 | 803 | $response = apply_filters( 'weforms_entry_submission_response', [ |
| 809 | - 'success' => true, | |
| 810 | - 'redirect_to' => $redirect_to, | |
| 804 | + 'success' => true, | |
| 805 | + 'redirect_to' => $redirect_to, | |
| 811 | 806 | 'show_message' => $show_message, |
| 812 | - 'message' => $message, | |
| 813 | - 'data' => $_POST, | |
| 814 | - 'form_id' => $form_id, | |
| 815 | - 'entry_id' => $entry_id, | |
| 816 | - 'entry_fields' =>$entry_fields, | |
| 807 | + 'message' => $message, | |
| 808 | + 'data' => $_POST, | |
| 809 | + 'form_id' => $form_id, | |
| 810 | + 'entry_id' => $entry_id, | |
| 817 | 811 | ] ); |
| 812 | + | |
| 813 | + $notification = new WeForms_Notification( [ | |
| 814 | + 'form_id' => $form_id, | |
| 815 | + 'page_id' => $page_id, | |
| 816 | + 'entry_id' => $entry_id, | |
| 817 | + ] ); | |
| 818 | + | |
| 819 | + $notification->send_notifications(); | |
| 820 | + | |
| 818 | 821 | weforms_clear_buffer(); |
| 819 | 822 | wp_send_json( $response ); |
| 820 | - } | |
| 823 | + } | |
| 821 | 824 | |
| 822 | - function validate_reCaptchav3( $secret ) { | |
| 823 | - check_ajax_referer( 'wpuf_form_add' ); | |
| 825 | + function validate_reCaptchav3( $secret ) { | |
| 826 | + check_ajax_referer( 'wpuf_form_add' ); | |
| 824 | 827 | |
| 825 | - $post_data = wp_unslash($_POST); | |
| 826 | - $token = $post_data['g-recaptcha-response']; | |
| 827 | - $action = $post_data['g-action']; | |
| 828 | - $google_captcha_url = esc_url( 'https://www.google.com/recaptcha/api/siteverify' ); | |
| 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' ); | |
| 829 | 832 | |
| 830 | - $response = wp_remote_post( $google_captcha_url, | |
| 831 | - array( | |
| 832 | - 'method' => 'POST', | |
| 833 | - 'body' => array( | |
| 834 | - 'secret' => $secret, | |
| 835 | - 'response' => $token | |
| 836 | - ) | |
| 833 | + $response = wp_remote_post( $google_captcha_url, | |
| 834 | + array( | |
| 835 | + 'method' => 'POST', | |
| 836 | + 'body' => array( | |
| 837 | + 'secret' => $secret, | |
| 838 | + 'response' => $token | |
| 837 | 839 | ) |
| 838 | - ); | |
| 840 | + ) | |
| 841 | + ); | |
| 839 | 842 | |
| 840 | 843 | |
| 841 | - if ( is_wp_error( $response ) ) { | |
| 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 { | |
| 842 | 854 | wp_send_json( [ |
| 843 | 855 | 'success' => false, |
| 844 | 856 | 'error' => __( 'reCAPTCHA validation failed', 'weforms' ), |
| 845 | 857 | ] ); |
| 846 | - } else { | |
| 847 | - $api_response = json_decode( wp_remote_retrieve_body( $response ), true ); | |
| 848 | - if( $api_response["success"] == '1' && $api_response["action"] == $action ) { | |
| 849 | - return true; | |
| 850 | - } else { | |
| 851 | - wp_send_json( [ | |
| 852 | - 'success' => false, | |
| 853 | - 'error' => __( 'reCAPTCHA validation failed', 'weforms' ), | |
| 854 | - ] ); | |
| 855 | - } | |
| 856 | 858 | } |
| 857 | 859 | } |
| 860 | + } | |
| 858 | 861 | /** |
| 859 | 862 | * reCaptcha Validation |
| 860 | 863 | * |
| 861 | 864 | * @return void |