PluginProbe
weForms – Easy Drag & Drop Contact Form Builder For WordPress / 1.6.15
weForms – Easy Drag & Drop Contact Form Builder For WordPress v1.6.15
1.6.7 1.6.8 1.6.9 1.6.12 1.6.13 1.6.14 1.6.15 1.6.16 1.6.17 1.6.18 1.6.19 1.6.2 1.6.20 1.6.21 1.6.22 1.6.23 1.6.24 1.6.25 1.6.26 1.6.27 1.6.28 1.6.3 1.6.4 1.6.5 1.6.6 All 74 releases
← All changes | includes/class-ajax.php +73 -64 1.6.61.6.15 View file →
@@ -109,8 +109,10 @@
109 109 $integrations = array();
110 110
111 111 if ( isset( $post_data['settings'] ) ) {
112 112 $settings = (array) json_decode( $post_data['settings'] );
113 + $settings['message'] = sanitize_text_field( $settings['message'] );
114 + error_log(print_r($settings, true));
113 115 } else {
114 116 $settings = isset( $form_data['wpuf_settings'] ) ? $form_data['wpuf_settings'] : [];
115 117 }
116 118
@@ -117,11 +119,8 @@
117 119 if ( isset( $post_data['integrations'] ) ) {
118 120 $integrations = (array) json_decode( $post_data['integrations'] );
119 121 }
120 122
121 - // $form_fields = wp_unslash( $form_fields );
122 - // $notifications = wp_unslash( $notifications );
123 -
124 123 $form_fields = json_decode( $form_fields, true );
125 124 $notifications = json_decode( $notifications, true );
126 125 $data = [
127 126 'form_id' => absint( $form_data['wpuf_form_id'] ),
@@ -134,8 +133,14 @@
134 133 ];
135 134
136 135 $form_fields = weforms()->form->save( $data );
137 136
137 + // Update Old Entry meta_key if changed
138 + $form_id = $form_data['wpuf_form_id'];
139 + $form = weforms()->form->get( $form_id );
140 +
141 + $form->maybe_update_entries( $form_fields );
142 +
138 143 do_action( 'weforms_update_form', $form_data['wpuf_form_id'], $form_fields, $settings );
139 144
140 145 wp_send_json_success( [ 'form_fields' => $form_fields ] );
141 146 }
@@ -524,9 +529,9 @@
524 529
525 530 $has_empty = false;
526 531 $answers = [];
527 532 $respondentPoints = isset( $form_settings['total_points'] ) ? floatval( $form_settings['total_points'] ) : 0;
528 -
533 + $fields_formatted = array();
529 534 foreach ( $fields as $key => $field ) {
530 535 if ( $form_settings['quiz_form'] == 'yes' ) {
531 536 $selectedAnswers = isset( $field['selected_answers'] ) ? $field['selected_answers'] : '';
532 537 $givenAnswer = isset( $field['value'] ) ? $field['value'] : '';
@@ -535,9 +540,8 @@
535 540 $fieldPoints = isset( $field['points'] ) ? floatval( $field['points'] ) : 0;
536 541
537 542 if ( $template == 'radio_field' || $template == 'dropdown_field' ) {
538 543 $answers[$field['name']] = true;
539 -
540 544 if ( empty( $givenAnswer ) ) {
541 545 $answers[$field['name']] = false;
542 546 $respondentPoints -= $fieldPoints;
543 547 } else {
@@ -572,13 +576,15 @@
572 576 }
573 577 } elseif ( empty( $field['value'] ) ) {
574 578 $has_empty = true;
575 579 break;
580 + } else {
581 + $field = WeForms_Form_Entry_Manager::format_entry_value( $field );
582 + array_push( $fields_formatted, $field );
576 583 }
577 584 }
578 -
579 585 $response = [
580 - 'form_fields' => $fields,
586 + 'form_fields' => $fields_formatted,
581 587 'form_settings' => $form_settings,
582 588 'meta_data' => $metadata,
583 589 'payment_data' => $payment,
584 590 'has_empty' => $has_empty,
@@ -585,8 +591,9 @@
585 591 'respondent_points' => $respondentPoints,
586 592 'answers' => $answers,
587 593 ];
588 594
595 +
589 596 wp_send_json_success( $response );
590 597 }
591 598
592 599 /**
@@ -695,9 +702,8 @@
695 702 * @return void
696 703 */
697 704 public function handle_frontend_submission() {
698 705 check_ajax_referer( 'wpuf_form_add' );
699 -
700 706 $form_id = isset( $_POST['form_id'] ) ? intval( $_POST['form_id'] ) : 0;
701 707 $page_id = isset( $_POST['page_id'] ) ? intval( $_POST['page_id'] ) : 0;
702 708
703 709 $form = weforms()->form->get( $form_id );
@@ -755,23 +761,40 @@
755 761 $this->validate_submission( $entry_fields, $form, $form_settings, $form_fields );
756 762
757 763 $entry_fields = apply_filters( 'weforms_before_entry_submission', $entry_fields, $form, $form_settings, $form_fields );
758 764
759 - $entry_id = weforms_insert_entry( [
760 - 'form_id' => $form_id,
761 - ], $entry_fields );
762 -
763 - if ( is_wp_error( $entry_id ) ) {
765 + //check for entry_fields for a return error
766 + if ( is_wp_error( $entry_fields ) ) {
764 767 wp_send_json( [
765 768 'success' => false,
766 - 'error' => $entry_id->get_error_message(),
769 + 'error' => $entry_fields->get_error_message(),
767 770 ] );
771 + } else {
772 + $entry_id = 1;
773 + $global_settings = weforms_get_settings();
774 + if ( empty( $form_settings['after_submission'] ) ) {
775 + $entry_id = weforms_insert_entry( [
776 + 'form_id' => $form_id,
777 + ], $entry_fields );
778 + if ( is_wp_error( $entry_id ) ) {
779 + wp_send_json( [
780 + 'success' => false,
781 + 'error' => $entry_id->get_error_message(),
782 + ] );
783 + }
784 + // Fire a hook for integration
785 + do_action( 'weforms_entry_submission', $entry_id, $form_id, $page_id, $form_settings );
786 + $notification = new WeForms_Notification( [
787 + 'form_id' => $form_id,
788 + 'page_id' => $page_id,
789 + 'entry_id' => $entry_id,
790 + ] );
791 + $notification->send_notifications();
792 + }
768 793 }
769 -
770 794 // redirect URL
771 795 $show_message = false;
772 - $redirect_to = false;
773 -
796 + $redirect_to = false;
774 797 if ( $form_settings['redirect_to'] == 'page' ) {
775 798 $redirect_to = get_permalink( $form_settings['page_id'] );
776 799 } elseif ( $form_settings['redirect_to'] == 'url' ) {
777 800 $redirect_to = $form_settings['url'];
@@ -779,17 +802,11 @@
779 802 $show_message = true;
780 803 } else {
781 804 $show_message = true;
782 805 }
783 -
784 - // Fire a hook for integration
785 - do_action( 'weforms_entry_submission', $entry_id, $form_id, $page_id, $form_settings );
786 -
787 806 $field_search = $field_replace = [];
788 -
789 807 foreach ( $form_fields as $r_field ) {
790 808 $field_search[] = '{' . $r_field['name'] . '}';
791 -
792 809 if ( $r_field['template'] == 'name_field' ) {
793 810 $field_replace[] = implode( ' ', explode( '|', $entry_fields[ $r_field['name'] ] ) );
794 811 } else if ( $r_field['template'] == 'address_field' ) {
795 812 $field_replace[] = implode( ', ', $entry_fields[ $r_field['name'] ] );
@@ -797,68 +814,60 @@
797 814 $field_replace[] = isset( $entry_fields[ $r_field['name'] ] ) ? $entry_fields[ $r_field['name'] ] : '';
798 815 }
799 816 }
800 817 $message = str_replace( $field_search, $field_replace, $form_settings['message'] );
801 -
802 818 // send the response
803 819 $response = apply_filters( 'weforms_entry_submission_response', [
804 - 'success' => true,
805 - 'redirect_to' => $redirect_to,
820 + 'success' => true,
821 + 'redirect_to' => $redirect_to,
806 822 'show_message' => $show_message,
807 - 'message' => $message,
808 - 'data' => $_POST,
809 - 'form_id' => $form_id,
810 - 'entry_id' => $entry_id,
823 + 'message' => $message,
824 + 'data' => $_POST,
825 + 'form_id' => $form_id,
826 + 'entry_id' => $entry_id,
827 + 'entry_fields' =>$entry_fields,
811 828 ] );
812 829
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 -
821 830 weforms_clear_buffer();
822 831 wp_send_json( $response );
823 - }
832 + }
824 833
825 - function validate_reCaptchav3( $secret ) {
826 - check_ajax_referer( 'wpuf_form_add' );
834 + function validate_reCaptchav3( $secret ) {
835 + check_ajax_referer( 'wpuf_form_add' );
827 836
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' );
837 + $post_data = wp_unslash($_POST);
838 + $token = $post_data['g-recaptcha-response'];
839 + $action = $post_data['g-action'];
840 + $google_captcha_url = esc_url( 'https://www.google.com/recaptcha/api/siteverify' );
832 841
833 - $response = wp_remote_post( $google_captcha_url,
834 - array(
835 - 'method' => 'POST',
836 - 'body' => array(
837 - 'secret' => $secret,
838 - 'response' => $token
842 + $response = wp_remote_post( $google_captcha_url,
843 + array(
844 + 'method' => 'POST',
845 + 'body' => array(
846 + 'secret' => $secret,
847 + 'response' => $token
848 + )
839 849 )
840 - )
841 - );
850 + );
842 851
843 852
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 {
853 + if ( is_wp_error( $response ) ) {
854 854 wp_send_json( [
855 855 'success' => false,
856 856 'error' => __( 'reCAPTCHA validation failed', 'weforms' ),
857 857 ] );
858 + } else {
859 + $api_response = json_decode( wp_remote_retrieve_body( $response ), true );
860 + if( $api_response["success"] == '1' && $api_response["action"] == $action ) {
861 + return true;
862 + } else {
863 + wp_send_json( [
864 + 'success' => false,
865 + 'error' => __( 'reCAPTCHA validation failed', 'weforms' ),
866 + ] );
867 + }
858 868 }
859 869 }
860 - }
861 870 /**
862 871 * reCaptcha Validation
863 872 *
864 873 * @return void