| @@ -108,11 +108,12 @@ | ||
| 108 | 108 | $settings = array(); |
| 109 | 109 | $integrations = array(); |
| 110 | 110 | |
| 111 | 111 | if ( isset( $post_data['settings'] ) ) { |
| 112 | - $settings = (array) json_decode( $post_data['settings'] ); | |
| 113 | - $settings['message'] = sanitize_text_field( $settings['message'] ); | |
| 114 | - error_log(print_r($settings, true)); | |
| 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'] ); | |
| 115 | 116 | } else { |
| 116 | 117 | $settings = isset( $form_data['wpuf_settings'] ) ? $form_data['wpuf_settings'] : []; |
| 117 | 118 | } |
| 118 | 119 | |
| @@ -141,9 +142,14 @@ | ||
| 141 | 142 | $form->maybe_update_entries( $form_fields ); |
| 142 | 143 | |
| 143 | 144 | do_action( 'weforms_update_form', $form_data['wpuf_form_id'], $form_fields, $settings ); |
| 144 | 145 | |
| 145 | - wp_send_json_success( [ 'form_fields' => $form_fields ] ); | |
| 146 | + wp_send_json_success( | |
| 147 | + array( | |
| 148 | + 'form_fields' => $form_fields, | |
| 149 | + 'settings' => $settings, | |
| 150 | + ) | |
| 151 | + ); | |
| 146 | 152 | } |
| 147 | 153 | |
| 148 | 154 | /** |
| 149 | 155 | * Get all contact forms |
| @@ -575,9 +581,9 @@ | ||
| 575 | 581 | } |
| 576 | 582 | } |
| 577 | 583 | } elseif ( empty( $field['value'] ) ) { |
| 578 | 584 | $has_empty = true; |
| 579 | - break; | |
| 585 | + continue; | |
| 580 | 586 | } else { |
| 581 | 587 | $field = WeForms_Form_Entry_Manager::format_entry_value( $field ); |
| 582 | 588 | array_push( $fields_formatted, $field ); |
| 583 | 589 | } |
| @@ -702,13 +708,24 @@ | ||
| 702 | 708 | * @return void |
| 703 | 709 | */ |
| 704 | 710 | public function handle_frontend_submission() { |
| 705 | 711 | check_ajax_referer( 'wpuf_form_add' ); |
| 706 | - | |
| 707 | 712 | $form_id = isset( $_POST['form_id'] ) ? intval( $_POST['form_id'] ) : 0; |
| 708 | 713 | $page_id = isset( $_POST['page_id'] ) ? intval( $_POST['page_id'] ) : 0; |
| 714 | + $form = weforms()->form->get( $form_id ); | |
| 709 | 715 | |
| 710 | - $form = weforms()->form->get( $form_id ); | |
| 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 | + | |
| 711 | 728 | $form_settings = $form->get_settings(); |
| 712 | 729 | $form_fields = $form->get_fields(); |
| 713 | 730 | $entry_fields = $form->prepare_entries(); |
| 714 | 731 | $form_entries = weforms_get_form_entries( $form_id, [ 'number' => '', 'offset' => '' ] ); |
| @@ -762,28 +779,36 @@ | ||
| 762 | 779 | $this->validate_submission( $entry_fields, $form, $form_settings, $form_fields ); |
| 763 | 780 | |
| 764 | 781 | $entry_fields = apply_filters( 'weforms_before_entry_submission', $entry_fields, $form, $form_settings, $form_fields ); |
| 765 | 782 | |
| 766 | - $entry_id = 1; | |
| 767 | - $global_settings = weforms_get_settings(); | |
| 768 | - if ( empty( $form_settings['after_submission'] ) ) { | |
| 769 | - $entry_id = weforms_insert_entry( [ | |
| 770 | - 'form_id' => $form_id, | |
| 771 | - ], $entry_fields ); | |
| 772 | - if ( is_wp_error( $entry_id ) ) { | |
| 773 | - wp_send_json( [ | |
| 774 | - 'success' => false, | |
| 775 | - 'error' => $entry_id->get_error_message(), | |
| 783 | + //check for entry_fields for a return error | |
| 784 | + if ( is_wp_error( $entry_fields ) ) { | |
| 785 | + wp_send_json( [ | |
| 786 | + 'success' => false, | |
| 787 | + 'error' => $entry_fields->get_error_message(), | |
| 788 | + ] ); | |
| 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, | |
| 776 | 808 | ] ); |
| 809 | + $notification->send_notifications(); | |
| 777 | 810 | } |
| 778 | - // Fire a hook for integration | |
| 779 | - do_action( 'weforms_entry_submission', $entry_id, $form_id, $page_id, $form_settings ); | |
| 780 | - $notification = new WeForms_Notification( [ | |
| 781 | - 'form_id' => $form_id, | |
| 782 | - 'page_id' => $page_id, | |
| 783 | - 'entry_id' => $entry_id, | |
| 784 | - ] ); | |
| 785 | - $notification->send_notifications(); | |
| 786 | 811 | } |
| 787 | 812 | // redirect URL |
| 788 | 813 | $show_message = false; |
| 789 | 814 | $redirect_to = false; |
| @@ -818,8 +843,9 @@ | ||
| 818 | 843 | 'form_id' => $form_id, |
| 819 | 844 | 'entry_id' => $entry_id, |
| 820 | 845 | 'entry_fields' =>$entry_fields, |
| 821 | 846 | ] ); |
| 847 | + | |
| 822 | 848 | weforms_clear_buffer(); |
| 823 | 849 | wp_send_json( $response ); |
| 824 | 850 | } |
| 825 | 851 | |