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