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 +68 -97 1.6.231.5.0 View file →
@@ -108,12 +108,9 @@
108 108 $settings = array();
109 109 $integrations = array();
110 110
111 111 if ( isset( $post_data['settings'] ) ) {
112 - $settings = json_decode( $post_data['settings'], true );
113 - $settings['message'] = sanitize_text_field( $settings['message'] );
114 - $settings['url'] = sanitize_url( $settings['url'] );
115 - $settings['limit_message'] = sanitize_text_field( $settings['limit_message'] );
112 + $settings = (array) json_decode( $post_data['settings'] );
116 113 } else {
117 114 $settings = isset( $form_data['wpuf_settings'] ) ? $form_data['wpuf_settings'] : [];
118 115 }
119 116
@@ -120,8 +117,11 @@
120 117 if ( isset( $post_data['integrations'] ) ) {
121 118 $integrations = (array) json_decode( $post_data['integrations'] );
122 119 }
123 120
121 + // $form_fields = wp_unslash( $form_fields );
122 + // $notifications = wp_unslash( $notifications );
123 +
124 124 $form_fields = json_decode( $form_fields, true );
125 125 $notifications = json_decode( $notifications, true );
126 126 $data = [
127 127 'form_id' => absint( $form_data['wpuf_form_id'] ),
@@ -134,22 +134,9 @@
134 134 ];
135 135
136 136 $form_fields = weforms()->form->save( $data );
137 137
138 - // Update Old Entry meta_key if changed
139 - $form_id = $form_data['wpuf_form_id'];
140 - $form = weforms()->form->get( $form_id );
141 -
142 - $form->maybe_update_entries( $form_fields );
143 -
144 - do_action( 'weforms_update_form', $form_data['wpuf_form_id'], $form_fields, $settings );
145 -
146 - wp_send_json_success(
147 - array(
148 - 'form_fields' => $form_fields,
149 - 'settings' => $settings,
150 - )
151 - );
138 + wp_send_json_success( [ 'form_fields' => $form_fields ] );
152 139 }
153 140
154 141 /**
155 142 * Get all contact forms
@@ -535,9 +522,9 @@
535 522
536 523 $has_empty = false;
537 524 $answers = [];
538 525 $respondentPoints = isset( $form_settings['total_points'] ) ? floatval( $form_settings['total_points'] ) : 0;
539 - $fields_formatted = array();
526 +
540 527 foreach ( $fields as $key => $field ) {
541 528 if ( $form_settings['quiz_form'] == 'yes' ) {
542 529 $selectedAnswers = isset( $field['selected_answers'] ) ? $field['selected_answers'] : '';
543 530 $givenAnswer = isset( $field['value'] ) ? $field['value'] : '';
@@ -546,8 +533,9 @@
546 533 $fieldPoints = isset( $field['points'] ) ? floatval( $field['points'] ) : 0;
547 534
548 535 if ( $template == 'radio_field' || $template == 'dropdown_field' ) {
549 536 $answers[$field['name']] = true;
537 +
550 538 if ( empty( $givenAnswer ) ) {
551 539 $answers[$field['name']] = false;
552 540 $respondentPoints -= $fieldPoints;
553 541 } else {
@@ -581,16 +569,14 @@
581 569 }
582 570 }
583 571 } elseif ( empty( $field['value'] ) ) {
584 572 $has_empty = true;
585 - continue;
586 - } else {
587 - $field = WeForms_Form_Entry_Manager::format_entry_value( $field );
588 - array_push( $fields_formatted, $field );
573 + break;
589 574 }
590 575 }
576 +
591 577 $response = [
592 - 'form_fields' => $fields_formatted,
578 + 'form_fields' => $fields,
593 579 'form_settings' => $form_settings,
594 580 'meta_data' => $metadata,
595 581 'payment_data' => $payment,
596 582 'has_empty' => $has_empty,
@@ -597,9 +583,8 @@
597 583 'respondent_points' => $respondentPoints,
598 584 'answers' => $answers,
599 585 ];
600 586
601 -
602 587 wp_send_json_success( $response );
603 588 }
604 589
605 590 /**
@@ -708,24 +693,13 @@
708 693 * @return void
709 694 */
710 695 public function handle_frontend_submission() {
711 696 check_ajax_referer( 'wpuf_form_add' );
697 +
712 698 $form_id = isset( $_POST['form_id'] ) ? intval( $_POST['form_id'] ) : 0;
713 699 $page_id = isset( $_POST['page_id'] ) ? intval( $_POST['page_id'] ) : 0;
700 +
714 701 $form = weforms()->form->get( $form_id );
715 -
716 - /**
717 - * Check if form submission is open. This resolves broken access control with unauthenticated users.
718 - * Access is now checked on frontend form rendering and submission.
719 - */
720 - $form_submission_status = $form->is_submission_open();
721 - if ( is_wp_error( $form_submission_status ) ) {
722 - wp_send_json( [
723 - 'success' => false,
724 - 'error' => __( 'Login Required for submission.', 'weforms' ),
725 - ] );
726 - }
727 -
728 702 $form_settings = $form->get_settings();
729 703 $form_fields = $form->get_fields();
730 704 $entry_fields = $form->prepare_entries();
731 705 $form_entries = weforms_get_form_entries( $form_id, [ 'number' => '', 'offset' => '' ] );
@@ -779,40 +753,23 @@
779 753 $this->validate_submission( $entry_fields, $form, $form_settings, $form_fields );
780 754
781 755 $entry_fields = apply_filters( 'weforms_before_entry_submission', $entry_fields, $form, $form_settings, $form_fields );
782 756
783 - //check for entry_fields for a return error
784 - 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 ) ) {
785 762 wp_send_json( [
786 763 'success' => false,
787 - 'error' => $entry_fields->get_error_message(),
764 + 'error' => $entry_id->get_error_message(),
788 765 ] );
789 - } else {
790 - $entry_id = 1;
791 - $global_settings = weforms_get_settings();
792 - if ( empty( $form_settings['after_submission'] ) ) {
793 - $entry_id = weforms_insert_entry( [
794 - 'form_id' => $form_id,
795 - ], $entry_fields );
796 - if ( is_wp_error( $entry_id ) ) {
797 - wp_send_json( [
798 - 'success' => false,
799 - 'error' => $entry_id->get_error_message(),
800 - ] );
801 - }
802 - // Fire a hook for integration
803 - do_action( 'weforms_entry_submission', $entry_id, $form_id, $page_id, $form_settings );
804 - $notification = new WeForms_Notification( [
805 - 'form_id' => $form_id,
806 - 'page_id' => $page_id,
807 - 'entry_id' => $entry_id,
808 - ] );
809 - $notification->send_notifications();
810 - }
811 766 }
767 +
812 768 // redirect URL
813 769 $show_message = false;
814 - $redirect_to = false;
770 + $redirect_to = false;
771 +
815 772 if ( $form_settings['redirect_to'] == 'page' ) {
816 773 $redirect_to = get_permalink( $form_settings['page_id'] );
817 774 } elseif ( $form_settings['redirect_to'] == 'url' ) {
818 775 $redirect_to = $form_settings['url'];
@@ -820,11 +777,17 @@
820 777 $show_message = true;
821 778 } else {
822 779 $show_message = true;
823 780 }
781 +
782 + // Fire a hook for integration
783 + do_action( 'weforms_entry_submission', $entry_id, $form_id, $page_id, $form_settings );
784 +
824 785 $field_search = $field_replace = [];
786 +
825 787 foreach ( $form_fields as $r_field ) {
826 788 $field_search[] = '{' . $r_field['name'] . '}';
789 +
827 790 if ( $r_field['template'] == 'name_field' ) {
828 791 $field_replace[] = implode( ' ', explode( '|', $entry_fields[ $r_field['name'] ] ) );
829 792 } else if ( $r_field['template'] == 'address_field' ) {
830 793 $field_replace[] = implode( ', ', $entry_fields[ $r_field['name'] ] );
@@ -832,60 +795,68 @@
832 795 $field_replace[] = isset( $entry_fields[ $r_field['name'] ] ) ? $entry_fields[ $r_field['name'] ] : '';
833 796 }
834 797 }
835 798 $message = str_replace( $field_search, $field_replace, $form_settings['message'] );
799 +
836 800 // send the response
837 801 $response = apply_filters( 'weforms_entry_submission_response', [
838 - 'success' => true,
839 - 'redirect_to' => $redirect_to,
802 + 'success' => true,
803 + 'redirect_to' => $redirect_to,
840 804 'show_message' => $show_message,
841 - 'message' => $message,
842 - 'data' => $_POST,
843 - 'form_id' => $form_id,
844 - 'entry_id' => $entry_id,
845 - 'entry_fields' =>$entry_fields,
805 + 'message' => $message,
806 + 'data' => $_POST,
807 + 'form_id' => $form_id,
808 + 'entry_id' => $entry_id,
846 809 ] );
847 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 +
848 819 weforms_clear_buffer();
849 820 wp_send_json( $response );
850 - }
821 + }
851 822
852 - function validate_reCaptchav3( $secret ) {
853 - check_ajax_referer( 'wpuf_form_add' );
823 + function validate_reCaptchav3( $secret ) {
824 + check_ajax_referer( 'wpuf_form_add' );
854 825
855 - $post_data = wp_unslash($_POST);
856 - $token = $post_data['g-recaptcha-response'];
857 - $action = $post_data['g-action'];
858 - $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' );
859 830
860 - $response = wp_remote_post( $google_captcha_url,
861 - array(
862 - 'method' => 'POST',
863 - 'body' => array(
864 - 'secret' => $secret,
865 - 'response' => $token
866 - )
831 + $response = wp_remote_post( $google_captcha_url,
832 + array(
833 + 'method' => 'POST',
834 + 'body' => array(
835 + 'secret' => $secret,
836 + 'response' => $token
867 837 )
868 - );
838 + )
839 + );
869 840
870 841
871 - 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 {
872 852 wp_send_json( [
873 853 'success' => false,
874 854 'error' => __( 'reCAPTCHA validation failed', 'weforms' ),
875 855 ] );
876 - } else {
877 - $api_response = json_decode( wp_remote_retrieve_body( $response ), true );
878 - if( $api_response["success"] == '1' && $api_response["action"] == $action ) {
879 - return true;
880 - } else {
881 - wp_send_json( [
882 - 'success' => false,
883 - 'error' => __( 'reCAPTCHA validation failed', 'weforms' ),
884 - ] );
885 - }
886 856 }
887 857 }
858 + }
888 859 /**
889 860 * reCaptcha Validation
890 861 *
891 862 * @return void