From 424c53504ec8f4dab1505ad6c6845cb9172be795 Mon Sep 17 00:00:00 2001 From: Sapayth Hossain Date: Mon, 4 Jul 2022 12:02:06 +0600 Subject: [PATCH 01/20] Inner column styles added --- assets/js/wpuf-form-builder-components.js | 4 +-- assets/less/admin.less | 3 +- assets/less/frontend-forms.less | 34 ++++++++++++++++++++++- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/assets/js/wpuf-form-builder-components.js b/assets/js/wpuf-form-builder-components.js index f32ffc7ce..672a9b3e4 100644 --- a/assets/js/wpuf-form-builder-components.js +++ b/assets/js/wpuf-form-builder-components.js @@ -449,8 +449,8 @@ Vue.component('field-options', { return self.$store.state.form_fields[i]; } - // check if the editing field belong to column field - if (self.$store.state.form_fields[i].template === 'column_field') { + // check if the editing field belong to column field or repeat field + if (self.$store.state.form_fields[i].template.match(/^(column|repeat)_field$/)) { var innerColumnFields = self.$store.state.form_fields[i].inner_fields; for (const columnFields in innerColumnFields) { diff --git a/assets/less/admin.less b/assets/less/admin.less index 3dae461e5..8a6bd30aa 100644 --- a/assets/less/admin.less +++ b/assets/less/admin.less @@ -818,7 +818,8 @@ ul.wpuf-form{ } } -#form-preview-stage .field-items .wpuf-field-columns + div.control-buttons{ +#form-preview-stage .field-items .wpuf-field-columns + div.control-buttons, +#form-preview-stage .field-items .wpuf-repeat-field + div.control-buttons{ top: 10px; z-index: 10; height: auto; diff --git a/assets/less/frontend-forms.less b/assets/less/frontend-forms.less index a2569a15b..935d8aefd 100644 --- a/assets/less/frontend-forms.less +++ b/assets/less/frontend-forms.less @@ -552,7 +552,7 @@ ul.wpuf-form { } } - table.wpuf-repeatable-field { + .wpuf-repeatable-field { border-collapse: collapse; & * { @@ -2050,6 +2050,38 @@ ul.wpuf-form{ } } } + .wpuf-repeatable-field{ + display: flex; + + &.has-columns-1{ + .wpuf-column{ + .wpuf-column-inner-fields{ + width: 90%; + } + } + } + + &.has-columns-2{ + .wpuf-column{ + .wpuf-column-inner-fields{ + width: 45%; + } + } + } + + &.has-columns-3{ + .wpuf-column{ + .wpuf-column-inner-fields{ + width: 30%; + } + } + } + + .wpuf-column-field-inner-columns{ + width: 90%; + } + + } } .ac_results { From 220a52fdbd3c83674c54c5e00882f4671afb4583 Mon Sep 17 00:00:00 2001 From: Sapayth Hossain Date: Mon, 4 Jul 2022 14:26:10 +0600 Subject: [PATCH 02/20] Reactivity fixed - Reactivity for field title, help etc fixed --- .../form-builder/assets/js/components/field-options/index.js | 2 +- admin/form-builder/assets/js/mixins/global.js | 4 ++-- assets/js/wpuf-form-builder-mixins.js | 4 ++-- assets/js/wpuf-form-builder-wpuf-forms.js | 2 +- assets/js/wpuf-form-builder.js | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/admin/form-builder/assets/js/components/field-options/index.js b/admin/form-builder/assets/js/components/field-options/index.js index 85f65fcaf..09a1bde98 100644 --- a/admin/form-builder/assets/js/components/field-options/index.js +++ b/admin/form-builder/assets/js/components/field-options/index.js @@ -34,7 +34,7 @@ Vue.component('field-options', { } // check if the editing field belong to column field - if (self.$store.state.form_fields[i].template === 'column_field') { + if (self.$store.state.form_fields[i].template.match(/^(column|repeat)_field$/)) { var innerColumnFields = self.$store.state.form_fields[i].inner_fields; for (const columnFields in innerColumnFields) { diff --git a/admin/form-builder/assets/js/mixins/global.js b/admin/form-builder/assets/js/mixins/global.js index 3992cee02..6ca829d88 100644 --- a/admin/form-builder/assets/js/mixins/global.js +++ b/admin/form-builder/assets/js/mixins/global.js @@ -58,8 +58,8 @@ Vue.mixin({ return true; } - // check if the single instance field exist in column fields - if (self.$store.state.form_fields[i].template === 'column_field') { + // check if the single instance field exist in column fields or repeat field + if (self.$store.state.form_fields[i].template.match(/^(column|repeat)_field$/)) { var innerColumnFields = self.$store.state.form_fields[i].inner_fields; for (const columnFields in innerColumnFields) { diff --git a/assets/js/wpuf-form-builder-mixins.js b/assets/js/wpuf-form-builder-mixins.js index 60b7ab770..736579410 100644 --- a/assets/js/wpuf-form-builder-mixins.js +++ b/assets/js/wpuf-form-builder-mixins.js @@ -164,8 +164,8 @@ Vue.mixin({ return true; } - // check if the single instance field exist in column fields - if (self.$store.state.form_fields[i].template === 'column_field') { + // check if the single instance field exist in column fields or repeat field + if (self.$store.state.form_fields[i].template.match(/^(column|repeat)_field$/)) { var innerColumnFields = self.$store.state.form_fields[i].inner_fields; for (const columnFields in innerColumnFields) { diff --git a/assets/js/wpuf-form-builder-wpuf-forms.js b/assets/js/wpuf-form-builder-wpuf-forms.js index 1bcfa3312..d6aa476be 100644 --- a/assets/js/wpuf-form-builder-wpuf-forms.js +++ b/assets/js/wpuf-form-builder-wpuf-forms.js @@ -28,7 +28,7 @@ } // check in column field - if (form_field.template === 'column_field' ) { + if (form_field.template.match(/^(column|repeat)_field$/)) { var innerColumnFields = form_field.inner_fields; for (const columnFields in innerColumnFields) { diff --git a/assets/js/wpuf-form-builder.js b/assets/js/wpuf-form-builder.js index 9a996b224..06daa1a94 100644 --- a/assets/js/wpuf-form-builder.js +++ b/assets/js/wpuf-form-builder.js @@ -130,7 +130,7 @@ } // check if the editing field belong to a column field - if (state.form_fields[i].template === 'column_field') { + if (state.form_fields[i].template.match(/^(column|repeat)_field$/)) { var innerColumnFields = state.form_fields[i].inner_fields; for (const columnFields in innerColumnFields) { From defb92267df8f64725b9808dee2fe753b9618f7d Mon Sep 17 00:00:00 2001 From: Sapayth Hossain Date: Tue, 5 Jul 2022 17:01:50 +0600 Subject: [PATCH 03/20] Backward compatibility added --- wpuf-functions.php | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/wpuf-functions.php b/wpuf-functions.php index 2ee82b9f1..6f60cfd9d 100644 --- a/wpuf-functions.php +++ b/wpuf-functions.php @@ -1728,8 +1728,32 @@ function wpuf_get_form_fields( $form_id ) { } // Add 'multiple' key for input_type:repeat - if ( 'repeat' === $field['input_type'] && ! isset( $field['multiple'] ) ) { - $field['multiple'] = ''; + if ( 'repeat' === $field['input_type'] ) { + if ( ! isset( $field['multiple'] ) ) { + $field['multiple'] = ''; + } + + // if old repeat field format + if ( empty( $field['inner_fields'] ) ) { + $field['template'] = 'text_field'; + + $field['inner_fields']['column-1'] = [ $field ]; + $field['inner_fields']['column-2'] = []; + $field['inner_fields']['column-3'] = []; + + $field['template'] = 'repeat_field'; + $field['columns'] = 1; + $field['min_column'] = 1; + $field['max_column'] = 3; + $field['column_space'] = 5; + } + + // if old repeat field format + if ( empty( $field['inner_columns_size'] ) ) { + $field['inner_columns_size']['column-1'] = '100%'; + $field['inner_columns_size']['column-2'] = '100%'; + $field['inner_columns_size']['column-3'] = '100%'; + } } if ( 'recaptcha' === $field['input_type'] ) { From 664ade788e5b5a548adc7010b1236761732a5b62 Mon Sep 17 00:00:00 2001 From: Sapayth Hossain Date: Tue, 5 Jul 2022 20:13:24 +0600 Subject: [PATCH 04/20] Inner field data mapped for backward compatibility --- wpuf-functions.php | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/wpuf-functions.php b/wpuf-functions.php index 6f60cfd9d..16705b5a8 100644 --- a/wpuf-functions.php +++ b/wpuf-functions.php @@ -1735,17 +1735,26 @@ function wpuf_get_form_fields( $form_id ) { // if old repeat field format if ( empty( $field['inner_fields'] ) ) { + $old_id = $field['id']; + $old_meta = $field['name']; + $old_label = $field['label']; $field['template'] = 'text_field'; + // set the new compatible values + $field['id'] = wpuf_form_field_id_generator(); + $field['label'] = ''; $field['inner_fields']['column-1'] = [ $field ]; $field['inner_fields']['column-2'] = []; $field['inner_fields']['column-3'] = []; - $field['template'] = 'repeat_field'; $field['columns'] = 1; $field['min_column'] = 1; $field['max_column'] = 3; $field['column_space'] = 5; + + $field['id'] = $old_id; + $field['label'] = $old_label; + $field['label'] = $old_label; } // if old repeat field format @@ -1770,6 +1779,18 @@ function wpuf_get_form_fields( $form_id ) { add_action( 'wp_ajax_wpuf_get_child_cat', 'wpuf_get_child_cats' ); add_action( 'wp_ajax_nopriv_wpuf_get_child_cat', 'wpuf_get_child_cats' ); +/* + * Generates a random integer for WPUF form field id + * like wpuf-form-builder-mixins.js + * + * @since WPUF + * + * @return int + */ +function wpuf_form_field_id_generator( $min = 999999, $max = 9999000001 ) { + return rand( $min, $max ); +} + /** * Returns child category dropdown on ajax request */ From feb7a3daa99c9f4819a628ace551a9272a51cdb5 Mon Sep 17 00:00:00 2001 From: Sapayth Hossain Date: Wed, 20 Jul 2022 09:54:58 +0600 Subject: [PATCH 05/20] ACF compatible --- .../js/components/field-options/index.js | 2 +- admin/form-builder/assets/js/form-builder.js | 4 +- assets/css/admin.css | 3 +- assets/js/frontend-form.js | 64 +++++++++++++++++-- assets/js/wpuf-form-builder.js | 2 +- includes/class-acf.php | 51 ++++++++++++++- includes/class-frontend-form-post.php | 4 +- includes/class-frontend-render-form.php | 46 +++++-------- wpuf-functions.php | 21 +++--- 9 files changed, 145 insertions(+), 52 deletions(-) diff --git a/admin/form-builder/assets/js/components/field-options/index.js b/admin/form-builder/assets/js/components/field-options/index.js index 09a1bde98..84bf6acf3 100644 --- a/admin/form-builder/assets/js/components/field-options/index.js +++ b/admin/form-builder/assets/js/components/field-options/index.js @@ -33,7 +33,7 @@ Vue.component('field-options', { return self.$store.state.form_fields[i]; } - // check if the editing field belong to column field + // check if the editing field belong to column field or repeat field if (self.$store.state.form_fields[i].template.match(/^(column|repeat)_field$/)) { var innerColumnFields = self.$store.state.form_fields[i].inner_fields; diff --git a/admin/form-builder/assets/js/form-builder.js b/admin/form-builder/assets/js/form-builder.js index 9a996b224..e49adeb94 100644 --- a/admin/form-builder/assets/js/form-builder.js +++ b/admin/form-builder/assets/js/form-builder.js @@ -129,8 +129,8 @@ } - // check if the editing field belong to a column field - if (state.form_fields[i].template === 'column_field') { + // check if the editing field belong to a column field or repeat field + if (state.form_fields[i].template.match(/^(column|repeat)_field$/)) { var innerColumnFields = state.form_fields[i].inner_fields; for (const columnFields in innerColumnFields) { diff --git a/assets/css/admin.css b/assets/css/admin.css index cdfbcdaad..1c8131313 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -626,7 +626,8 @@ ul.wpuf-form .wpuf-field-columns .wpuf-column-field-inner-columns .wpuf-column . margin: 0; padding: 15px 0; } -#form-preview-stage .field-items .wpuf-field-columns + div.control-buttons { +#form-preview-stage .field-items .wpuf-field-columns + div.control-buttons, +#form-preview-stage .field-items .wpuf-repeat-field + div.control-buttons { top: 10px; z-index: 10; height: auto; diff --git a/assets/js/frontend-form.js b/assets/js/frontend-form.js index 8f759e8d5..5b77975be 100644 --- a/assets/js/frontend-form.js +++ b/assets/js/frontend-form.js @@ -18,12 +18,15 @@ //enable multistep this.enableMultistep(this); + var form = $('.wpuf-form'); // clone and remove repeated field - $('.wpuf-form').on('click', 'img.wpuf-clone-field', this.cloneField); - $('.wpuf-form').on('click', 'img.wpuf-remove-field', this.removeField); - $('.wpuf-form').on('click', 'a.wpuf-delete-avatar', this.deleteAvatar); - $('.wpuf-form').on('click', 'a#wpuf-post-draft', this.draftPost); - $('.wpuf-form').on('click', 'button#wpuf-account-update-profile', this.account_update_profile); + form.on('click', 'img.wpuf-clone-field', this.cloneField); + form.on('click', 'img.wpuf-clone-repeat-field', this.cloneRepeatField); + form.on('click', 'img.wpuf-remove-field', this.removeField); + form.on('click', 'img.wpuf-remove-repeat-field', this.removeRepeatField); + form.on('click', 'a.wpuf-delete-avatar', this.deleteAvatar); + form.on('click', 'a#wpuf-post-draft', this.draftPost); + form.on('click', 'button#wpuf-account-update-profile', this.account_update_profile); $('.wpuf-form-add').on('submit', this.formSubmit); $('form#post').on('submit', this.adminPostSubmit); @@ -340,6 +343,57 @@ } }, + cloneRepeatField: function( e ) { + e.preventDefault(); + + var div = $( this ).closest( '.wpuf-column-field-inner-columns.column-repeat' ); + var clone = div.clone(); + + //clear the inputs + clone.find( 'input' ).val( '' ); + clone.find( 'textarea' ).val( '' ); + clone.find( ':checked' ).attr( 'checked', '' ); + div.after( clone ); + + WP_User_Frontend.calculateFieldsName( $( this ).parents( '.wpuf-field-columns' ) ); + }, + + removeRepeatField: function () { + //check if it's the only item + var parent = $( this ).closest( '.wpuf-column-field-inner-columns.column-repeat' ); + var items = parent.siblings().addBack().length; + + var row_parent = $( this ).parents( '.wpuf-field-columns' ); + + if( items > 1 ) { + parent.remove(); + } + + WP_User_Frontend.calculateFieldsName( row_parent ); + }, + + calculateFieldsName: function( parentItem ) { + var field_rows = parentItem.children(); + var field_names = []; + var field_ids = []; + var field_classes = []; + var fields_selector = '.wpuf-column input, .wpuf-column textarea, .wpuf-column select, .wpuf-column .wpuf-rich-validation'; + + $(field_rows[0]).find(fields_selector).each(function (i, item) { + field_names.push($(item).attr('name').split('_0_')); + field_ids.push($(item).attr('id').split('_0_')); + field_classes.push($(item).attr('class').split('_0_')); + }); + + field_rows.each(function(i, row){ + $(row).find(fields_selector).each(function(y, field) { + $(field).attr('name', field_names[y][0]+'_'+i+'_'+field_names[y][1]); + $(field).attr('id', field_ids[y][0]+'_'+i+'_'+field_ids[y][1]); + $(field).attr('class', field_classes[y][0]+'_'+i+'_'+field_classes[y][1]); + }); + }); + }, + adminPostSubmit: function(e) { e.preventDefault(); diff --git a/assets/js/wpuf-form-builder.js b/assets/js/wpuf-form-builder.js index 06daa1a94..e49adeb94 100644 --- a/assets/js/wpuf-form-builder.js +++ b/assets/js/wpuf-form-builder.js @@ -129,7 +129,7 @@ } - // check if the editing field belong to a column field + // check if the editing field belong to a column field or repeat field if (state.form_fields[i].template.match(/^(column|repeat)_field$/)) { var innerColumnFields = state.form_fields[i].inner_fields; diff --git a/includes/class-acf.php b/includes/class-acf.php index c5309e336..0622a8f6e 100644 --- a/includes/class-acf.php +++ b/includes/class-acf.php @@ -277,19 +277,59 @@ public function load_compatible_value( $value, $post_id, $field ) { * @param $meta_vars */ public function update_acf_field_meta( $post_id, $form_id, $form_settings, $meta_vars ) { - if ( ! $this->plugin_exists() ){ + if ( ! $this->plugin_exists() ) { return; } $groups = acf_get_field_groups( [ 'post_type' => $form_settings['post_type'] ] ); $existing_meta = get_post_meta( $post_id ); + $repeat_field_metas = []; + + foreach ( $meta_vars as $value ) { + // if this is a repeat field + if ( 'repeat_field' === $value['template'] && ! empty( $value['inner_fields'] ) ) { + $field_count = 0; + // loop for each columns. we have 3 columns for repeated fields + for ( $i = 1; $i <= 3; $i++ ) { + if ( ! empty( $value['inner_fields'][ 'column-' . $i ] ) ) { + foreach ( $value['inner_fields'][ 'column-' . $i ] as $column_value ) { + // get the meta key for the current inner field + $meta_key = ! empty( $column_value['name'] ) ? $column_value['name'] : ''; + if ( '' !== $meta_key ) { + // get the inner field value by matching the meta key + $inner_field_values = ! empty( $_POST[ $meta_key ] ) ? sanitize_text_field( wp_unslash( $_POST[ $meta_key ] ) ) : []; // phpcs:ignore WordPress.Security.NonceVerification + foreach ( $inner_field_values as $index => $inner_value ) { + $field_key = '_' . $value['name'] . '_' . $index . '_' . $meta_key; + $repeat_field_metas[ $index ][ $meta_key ] = $field_key; + } + } + + $field_count++; + } + } + } + + update_post_meta( $post_id, $value['name'], $field_count ); + // save repeat field data as ACF format + update_post_meta( $post_id, '_' . $value['name'], uniqid( 'field_' ) ); + } + } + + $acf_repeat_fields = []; foreach ( acf_get_fields( $groups ) as $group ) { $meta_key = '_' . $group['name']; $name = $group['name']; if ( 'repeater' === $group['type'] ) { $meta_key = 'repeater'; + + if ( ! empty( $group['sub_fields'] ) ) { + foreach ( $group['sub_fields'] as $sub_field ) { + $meta_key = ! empty( $sub_field['name'] ) ? $sub_field['name'] : ''; + $acf_repeat_fields[ $meta_key ] = ! empty( $sub_field['key'] ) ? $sub_field['key'] : ''; + } + } } //check key also in meta vars @@ -303,5 +343,14 @@ function ( $meta_var ) { update_post_meta( $post_id, $meta_key, $group['key'] ); } } + + foreach ( $repeat_field_metas as $fields ) { + foreach ( $fields as $key => $field ) { + $acf_id = ! empty( $acf_repeat_fields[ $key ] ) ? $acf_repeat_fields[ $key ] : ''; + if ( '' !== $acf_id ) { + update_post_meta( $post_id, $field, $acf_id ); + } + } + } } } diff --git a/includes/class-frontend-form-post.php b/includes/class-frontend-form-post.php index d3b6e2743..a1166bb3b 100755 --- a/includes/class-frontend-form-post.php +++ b/includes/class-frontend-form-post.php @@ -743,8 +743,8 @@ public static function update_post_meta( $meta_vars, $post_id ) { delete_post_meta( $post_id, $repeat_key ); // now add them - foreach ( $repeat_value as $repeat_field ) { - add_post_meta( $post_id, $repeat_key, $repeat_field ); + foreach ( $repeat_value as $key => $repeat_field ) { + add_post_meta( $post_id, $key, $repeat_field ); } } diff --git a/includes/class-frontend-render-form.php b/includes/class-frontend-render-form.php index 11fa1a58c..602ca2e93 100644 --- a/includes/class-frontend-render-form.php +++ b/includes/class-frontend-render-form.php @@ -734,38 +734,26 @@ public static function prepare_meta_fields( $meta_vars ) { break; case 'repeat': - $repeater_value = wp_unslash( $_POST[ $value['name'] ] ); // WPCS: sanitization ok. - - // if it is a multi column repeat field - if ( isset( $value['multiple'] ) && $value['multiple'] == 'true' ) { - - // if there's any items in the array, process it - if ( $repeater_value ) { - $ref_arr = array(); - $cols = count( $value['columns'] ); - $first = array_shift( array_values( $repeater_value ) ); //first element - $rows = count( $first ); - - // loop through columns - for ( $i = 0; $i < $rows; $i++ ) { - - // loop through the rows and store in a temp array - $temp = array(); - for ( $j = 0; $j < $cols; $j++ ) { - $temp[] = $repeater_value[ $j ][ $i ]; + // loop for each columns. we have 3 columns for repeated fields + for ( $i = 1; $i <= 3; $i++ ) { + $index = 0; + if ( ! empty( $value['inner_fields'] ) && ! empty( $value['inner_fields'][ 'column-' . $i ] ) ) { + foreach ( $value['inner_fields'][ 'column-' . $i ] as $column_value ) { + $meta_key = ! empty( $column_value['name'] ) ? $column_value['name'] : ''; + $formatted_key = $value['name'] . '_' . $index . '_' . $meta_key; + + if ( '' !== $meta_key ) { + while ( isset( $_POST[ $formatted_key ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification + if ( ! empty( $_POST[ $formatted_key ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification + $meta_key_value[ $formatted_key ] = wp_unslash( $_POST[ $formatted_key ] ); + } + + $index++; + $formatted_key = $value['name'] . '_' . $index . '_' . $meta_key; + } } - - // store all fields in a row with self::$separator separated - $ref_arr[] = implode( self::$separator, $temp ); - } - - // now, if we found anything in $ref_arr, store to $multi_repeated - if ( $ref_arr ) { - $multi_repeated[ $value['name'] ] = array_slice( $ref_arr, 0, $rows ); } } - } else { - $meta_key_value[ $value['name'] ] = implode( self::$separator, $repeater_value ); } break; diff --git a/wpuf-functions.php b/wpuf-functions.php index 16705b5a8..820702d8e 100644 --- a/wpuf-functions.php +++ b/wpuf-functions.php @@ -1738,23 +1738,25 @@ function wpuf_get_form_fields( $form_id ) { $old_id = $field['id']; $old_meta = $field['name']; $old_label = $field['label']; + $new_id = wpuf_form_field_id_generator(); $field['template'] = 'text_field'; // set the new compatible values - $field['id'] = wpuf_form_field_id_generator(); - $field['label'] = ''; + $field['id'] = $new_id; + $field['name'] = $old_meta . '_' . $new_id; + $field['label'] = ''; $field['inner_fields']['column-1'] = [ $field ]; $field['inner_fields']['column-2'] = []; $field['inner_fields']['column-3'] = []; - $field['template'] = 'repeat_field'; - $field['columns'] = 1; - $field['min_column'] = 1; - $field['max_column'] = 3; - $field['column_space'] = 5; + $field['template'] = 'repeat_field'; + $field['columns'] = 1; + $field['min_column'] = 1; + $field['max_column'] = 3; + $field['column_space'] = 5; $field['id'] = $old_id; $field['label'] = $old_label; - $field['label'] = $old_label; + $field['name'] = $old_meta; } // if old repeat field format @@ -1780,8 +1782,7 @@ function wpuf_get_form_fields( $form_id ) { add_action( 'wp_ajax_nopriv_wpuf_get_child_cat', 'wpuf_get_child_cats' ); /* - * Generates a random integer for WPUF form field id - * like wpuf-form-builder-mixins.js + * Generates a random integer for WPUF form field id like wpuf-form-builder-mixins.js * * @since WPUF * From fc236eee74204f2765468d321ebac1fff99b3f0b Mon Sep 17 00:00:00 2001 From: Sapayth Hossain Date: Wed, 20 Jul 2022 11:26:09 +0600 Subject: [PATCH 06/20] CS fix and slight optimization Slight optimization when removing the fields --- assets/js/frontend-form.js | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/assets/js/frontend-form.js b/assets/js/frontend-form.js index 5b77975be..4e87189c1 100644 --- a/assets/js/frontend-form.js +++ b/assets/js/frontend-form.js @@ -361,15 +361,19 @@ removeRepeatField: function () { //check if it's the only item var parent = $( this ).closest( '.wpuf-column-field-inner-columns.column-repeat' ); - var items = parent.siblings().addBack().length; + var allItems = parent.siblings().addBack(); + var itemsLength = allItems.length; - var row_parent = $( this ).parents( '.wpuf-field-columns' ); + var fieldIndex = $( allItems ).index( $( this ).closest( '.wpuf-column-field-inner-columns.column-repeat' ) ); - if( items > 1 ) { + if ( itemsLength > 1 ) { parent.remove(); } - WP_User_Frontend.calculateFieldsName( row_parent ); + // calculate only if the removed item is not the last item + if ( fieldIndex + 1 !== itemsLength ) { + WP_User_Frontend.calculateFieldsName( parent ); + } }, calculateFieldsName: function( parentItem ) { @@ -379,17 +383,17 @@ var field_classes = []; var fields_selector = '.wpuf-column input, .wpuf-column textarea, .wpuf-column select, .wpuf-column .wpuf-rich-validation'; - $(field_rows[0]).find(fields_selector).each(function (i, item) { - field_names.push($(item).attr('name').split('_0_')); - field_ids.push($(item).attr('id').split('_0_')); - field_classes.push($(item).attr('class').split('_0_')); + $( field_rows[0] ).find( fields_selector ).each( function ( i, item ) { + field_names.push( $( item ).attr( 'name' ).split( '_0_' ) ); + field_ids.push( $( item ).attr( 'id' ).split( '_0_' ) ); + field_classes.push( $( item ).attr( 'class' ).split( '_0_' ) ); }); - field_rows.each(function(i, row){ - $(row).find(fields_selector).each(function(y, field) { - $(field).attr('name', field_names[y][0]+'_'+i+'_'+field_names[y][1]); - $(field).attr('id', field_ids[y][0]+'_'+i+'_'+field_ids[y][1]); - $(field).attr('class', field_classes[y][0]+'_'+i+'_'+field_classes[y][1]); + field_rows.each( function( i, row ) { + $( row ).find( fields_selector ).each( function( y, field ) { + $( field ).attr( 'name', field_names[y][0] + '_' + i + '_' + field_names[y][1] ); + $( field ).attr( 'id', field_ids[y][0] + '_' + i + '_' + field_ids[y][1] ); + $( field ).attr( 'class', field_classes[y][0] + '_' + i + '_' + field_classes[y][1] ); }); }); }, From b4e6974a6f89567dcd7745c65240daf2cb68cfb8 Mon Sep 17 00:00:00 2001 From: Sapayth Hossain Date: Fri, 22 Jul 2022 10:22:00 +0600 Subject: [PATCH 07/20] Sub fields value edit properly --- assets/js/frontend-form.js | 10 +++++ includes/class-acf.php | 55 +------------------------ includes/class-frontend-form-post.php | 47 ++++++++++++++++----- includes/class-frontend-render-form.php | 18 ++++---- 4 files changed, 57 insertions(+), 73 deletions(-) diff --git a/assets/js/frontend-form.js b/assets/js/frontend-form.js index 4e87189c1..ae9fc4531 100644 --- a/assets/js/frontend-form.js +++ b/assets/js/frontend-form.js @@ -356,6 +356,7 @@ div.after( clone ); WP_User_Frontend.calculateFieldsName( $( this ).parents( '.wpuf-field-columns' ) ); + WP_User_Frontend.setRowNumber( $( this ).closest( '.wpuf-field-columns' ) ); }, removeRepeatField: function () { @@ -367,6 +368,7 @@ var fieldIndex = $( allItems ).index( $( this ).closest( '.wpuf-column-field-inner-columns.column-repeat' ) ); if ( itemsLength > 1 ) { + WP_User_Frontend.setRowNumber( $( parent ).closest( '.wpuf-field-columns' ), itemsLength - 1 ); parent.remove(); } @@ -376,6 +378,14 @@ } }, + setRowNumber: function ( parent, length ) { + if ( ! length ) { + length = $( parent ).children().length; + } + + $( parent ).parent( '.wpuf-fields' ).find( 'input.repeat_row_numbers' ).val( length ); + }, + calculateFieldsName: function( parentItem ) { var field_rows = parentItem.children(); var field_names = []; diff --git a/includes/class-acf.php b/includes/class-acf.php index 0622a8f6e..5e4886c89 100644 --- a/includes/class-acf.php +++ b/includes/class-acf.php @@ -277,61 +277,17 @@ public function load_compatible_value( $value, $post_id, $field ) { * @param $meta_vars */ public function update_acf_field_meta( $post_id, $form_id, $form_settings, $meta_vars ) { - if ( ! $this->plugin_exists() ) { + if ( ! $this->plugin_exists() ){ return; } $groups = acf_get_field_groups( [ 'post_type' => $form_settings['post_type'] ] ); $existing_meta = get_post_meta( $post_id ); - $repeat_field_metas = []; - - foreach ( $meta_vars as $value ) { - // if this is a repeat field - if ( 'repeat_field' === $value['template'] && ! empty( $value['inner_fields'] ) ) { - $field_count = 0; - // loop for each columns. we have 3 columns for repeated fields - for ( $i = 1; $i <= 3; $i++ ) { - if ( ! empty( $value['inner_fields'][ 'column-' . $i ] ) ) { - foreach ( $value['inner_fields'][ 'column-' . $i ] as $column_value ) { - // get the meta key for the current inner field - $meta_key = ! empty( $column_value['name'] ) ? $column_value['name'] : ''; - if ( '' !== $meta_key ) { - // get the inner field value by matching the meta key - $inner_field_values = ! empty( $_POST[ $meta_key ] ) ? sanitize_text_field( wp_unslash( $_POST[ $meta_key ] ) ) : []; // phpcs:ignore WordPress.Security.NonceVerification - foreach ( $inner_field_values as $index => $inner_value ) { - $field_key = '_' . $value['name'] . '_' . $index . '_' . $meta_key; - $repeat_field_metas[ $index ][ $meta_key ] = $field_key; - } - } - - $field_count++; - } - } - } - - update_post_meta( $post_id, $value['name'], $field_count ); - // save repeat field data as ACF format - update_post_meta( $post_id, '_' . $value['name'], uniqid( 'field_' ) ); - } - } - - $acf_repeat_fields = []; foreach ( acf_get_fields( $groups ) as $group ) { $meta_key = '_' . $group['name']; $name = $group['name']; - if ( 'repeater' === $group['type'] ) { - $meta_key = 'repeater'; - - if ( ! empty( $group['sub_fields'] ) ) { - foreach ( $group['sub_fields'] as $sub_field ) { - $meta_key = ! empty( $sub_field['name'] ) ? $sub_field['name'] : ''; - $acf_repeat_fields[ $meta_key ] = ! empty( $sub_field['key'] ) ? $sub_field['key'] : ''; - } - } - } - //check key also in meta vars $meta_keys = array_map( function ( $meta_var ) { @@ -343,14 +299,5 @@ function ( $meta_var ) { update_post_meta( $post_id, $meta_key, $group['key'] ); } } - - foreach ( $repeat_field_metas as $fields ) { - foreach ( $fields as $key => $field ) { - $acf_id = ! empty( $acf_repeat_fields[ $key ] ) ? $acf_repeat_fields[ $key ] : ''; - if ( '' !== $acf_id ) { - update_post_meta( $post_id, $field, $acf_id ); - } - } - } } } diff --git a/includes/class-frontend-form-post.php b/includes/class-frontend-form-post.php index a1166bb3b..77fb624e0 100755 --- a/includes/class-frontend-form-post.php +++ b/includes/class-frontend-form-post.php @@ -704,7 +704,7 @@ public function add_post_shortcode( $atts ) { public static function update_post_meta( $meta_vars, $post_id ) { // check_ajax_referer( 'wpuf_form_add' ); // prepare the meta vars - list( $meta_key_value, $multi_repeated, $files ) = self::prepare_meta_fields( $meta_vars ); + list( $meta_key_value, $repeat_fields, $files ) = self::prepare_meta_fields( $meta_vars ); // set featured image if there's any // @codingStandardsIgnoreStart @@ -732,22 +732,47 @@ public static function update_post_meta( $meta_vars, $post_id ) { } } - // save all custom fields - foreach ( $meta_key_value as $meta_key => $meta_value ) { - update_post_meta( $post_id, $meta_key, $meta_value ); + // delete previous repeat values + if ( ! empty( $repeat_fields ) ) { + $row_num = get_post_meta( $post_id, $repeat_fields['repeat_meta'], true ); + + if ( $row_num ) { + $sub_fields = ! empty( $repeat_fields['sub_fields'] ) ? $repeat_fields['sub_fields'] : []; + for ( $i = 0; $i <= $row_num; $i++ ) { + foreach ( $sub_fields as $value ) { + $field_meta = $repeat_fields['repeat_meta'] . '_' . $i . '_' . $value; + delete_post_meta( $post_id, $field_meta ); + delete_post_meta( $post_id, '_' . $field_meta ); + } + } + } } - // save any multicolumn repeatable fields - foreach ( $multi_repeated as $repeat_key => $repeat_value ) { - // first, delete any previous repeatable fields - delete_post_meta( $post_id, $repeat_key ); + // insert acf compatible data + if ( ! empty( $repeat_fields ) ) { + if ( ! empty( $meta_key_value[ $repeat_fields['repeat_meta'] ] ) ) { + $row_number = $meta_key_value[ $repeat_fields['repeat_meta'] ]; + + if ( ! empty( $row_number ) ) { + $sub_fields = ! empty( $repeat_fields['sub_fields'] ) ? $repeat_fields['sub_fields'] : []; - // now add them - foreach ( $repeat_value as $key => $repeat_field ) { - add_post_meta( $post_id, $key, $repeat_field ); + for ( $i = 0; $i < $row_num; $i++ ) { + foreach ( $sub_fields as $value ) { + $field_meta = $repeat_fields['repeat_meta'] . '_' . $i . '_' . $value; + update_post_meta( $post_id, '_' . $field_meta, uniqid( 'field_' ) ); + } + } + } } } + + + // save all custom fields + foreach ( $meta_key_value as $meta_key => $meta_value ) { + update_post_meta( $post_id, $meta_key, $meta_value ); + } + // save any files attached foreach ( $files as $file_input ) { // delete any previous value diff --git a/includes/class-frontend-render-form.php b/includes/class-frontend-render-form.php index 602ca2e93..0ec658120 100644 --- a/includes/class-frontend-render-form.php +++ b/includes/class-frontend-render-form.php @@ -699,7 +699,7 @@ public static function prepare_meta_fields( $meta_vars ) { $post_data = wp_unslash( $_POST ); // phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped $files = []; $meta_key_value = []; - $multi_repeated = []; //multi repeated fields will in sotre duplicated meta key + $repeat_fields = []; // repeat field and sub-fields data foreach ( $meta_vars as $key => $value ) { $wpuf_field = wpuf()->fields->get_field( $value['template'] ); @@ -734,20 +734,20 @@ public static function prepare_meta_fields( $meta_vars ) { break; case 'repeat': + $row_count_key = $value['name'] . '_row_num'; + $row_number = ! empty( $_POST[ $row_count_key ] ) ? absint( wp_unslash( $_POST[ $row_count_key ] ) ) : 1; // phpcs:ignore WordPress.Security.NonceVerification + // loop for each columns. we have 3 columns for repeated fields for ( $i = 1; $i <= 3; $i++ ) { - $index = 0; if ( ! empty( $value['inner_fields'] ) && ! empty( $value['inner_fields'][ 'column-' . $i ] ) ) { foreach ( $value['inner_fields'][ 'column-' . $i ] as $column_value ) { + $index = 0; $meta_key = ! empty( $column_value['name'] ) ? $column_value['name'] : ''; $formatted_key = $value['name'] . '_' . $index . '_' . $meta_key; - if ( '' !== $meta_key ) { + $repeat_fields['sub_fields'][] = $meta_key; while ( isset( $_POST[ $formatted_key ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification - if ( ! empty( $_POST[ $formatted_key ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification - $meta_key_value[ $formatted_key ] = wp_unslash( $_POST[ $formatted_key ] ); - } - + $meta_key_value[ $formatted_key ] = wp_unslash( $_POST[ $formatted_key ] ); $index++; $formatted_key = $value['name'] . '_' . $index . '_' . $meta_key; } @@ -755,6 +755,8 @@ public static function prepare_meta_fields( $meta_vars ) { } } } + $meta_key_value[ $value['name'] ] = $row_number; + $repeat_fields['repeat_meta'] = $value['name']; break; @@ -824,7 +826,7 @@ public static function prepare_meta_fields( $meta_vars ) { break; } } //end foreach - return [ $meta_key_value, $multi_repeated, $files ]; + return [ $meta_key_value, $repeat_fields, $files ]; } /** From c2c080f7ce68007915aa8f68b1ba0fa1125809f9 Mon Sep 17 00:00:00 2001 From: Sapayth Hossain Date: Tue, 12 Sep 2023 17:48:31 +0600 Subject: [PATCH 08/20] show post values in the post --- assets/css/frontend-forms.css | 83 +++++++----- assets/less/frontend-forms.less | 101 +++++++-------- includes/class-frontend-form-post.php | 4 +- wpuf-functions.php | 173 +++++++++++++++++++++++++- 4 files changed, 273 insertions(+), 88 deletions(-) diff --git a/assets/css/frontend-forms.css b/assets/css/frontend-forms.css index f58e99878..982cc4f72 100644 --- a/assets/css/frontend-forms.css +++ b/assets/css/frontend-forms.css @@ -1,6 +1,5 @@ /* DivTable.com */ body { - font-family: 'Open Sans', sans-serif; /* css for timepicker */ /** author info **/ /** jQuery Suggest **/ @@ -189,6 +188,11 @@ body #form-preview-stage.wpuf-style ul.wpuf-form .wpuf-fields select[multiple], body .wpuf-form-add.wpuf-style ul.wpuf-form .wpuf-fields select[multiple] { height: auto; } +body #form-preview-stage.wpuf-style ul.wpuf-form .wpuf-fields-inline, +body .wpuf-form-add.wpuf-style ul.wpuf-form .wpuf-fields-inline { + display: flex; + justify-content: space-between; +} body #form-preview-stage.wpuf-style ul.wpuf-form .wpuf-submit input[type=submit], body .wpuf-form-add.wpuf-style ul.wpuf-form .wpuf-submit input[type=submit] { font-size: 16px; @@ -238,7 +242,11 @@ body ul.wpuf-form li.has-error { body ul.wpuf-form li .wp-editor-wrap { border: 1px solid #eee; } -body ul.wpuf-form li.wpuf_hidden_field { +body ul.wpuf-form liwpuf-el { + position: relative; + display: flex; +} +body ul.wpuf-form li.wpuf_hidden_field.wpuf-el { display: none; } body ul.wpuf-form li .wpuf-label { @@ -346,7 +354,8 @@ body ul.wpuf-form li .wpuf-fields .wpuf-name-field-wrap.format-first-middle-last float: right; width: 37%; } -body ul.wpuf-form li .wpuf-fields .wpuf-help { +body ul.wpuf-form li .wpuf-fields .wpuf-help, +body ul.wpuf-form li .wpuf-fields .wpuf-wordlimit-message { color: #666; margin: 2px 0 5px 0; font-size: 12px; @@ -354,14 +363,18 @@ body ul.wpuf-form li .wpuf-fields .wpuf-help { font-family: sans-serif; display: block; } -body ul.wpuf-form li .wpuf-fields .wpuf-help .text-danger { +body ul.wpuf-form li .wpuf-fields .wpuf-help .text-danger, +body ul.wpuf-form li .wpuf-fields .wpuf-wordlimit-message .text-danger { color: red; } -body ul.wpuf-form li .wpuf-fields .wpuf-help .text-success { +body ul.wpuf-form li .wpuf-fields .wpuf-help .text-success, +body ul.wpuf-form li .wpuf-fields .wpuf-wordlimit-message .text-success { color: green; } body ul.wpuf-form li .wpuf-fields .wpuf-help #url-alart, -body ul.wpuf-form li .wpuf-fields .wpuf-help #url-alart-mgs { +body ul.wpuf-form li .wpuf-fields .wpuf-wordlimit-message #url-alart, +body ul.wpuf-form li .wpuf-fields .wpuf-help #url-alart-mgs, +body ul.wpuf-form li .wpuf-fields .wpuf-wordlimit-message #url-alart-mgs { font-style: normal; font-size: 16px; } @@ -491,24 +504,32 @@ body ul.wpuf-form li .wpuf-fields .wpuf-fields-list.wpuf-list-inline li { padding-left: 5px; padding-right: 5px; } -body ul.wpuf-form li .wpuf-fields table.wpuf-repeatable-field { +body ul.wpuf-form li .wpuf-fields .wpuf-repeatable-field { border-collapse: collapse; } -body ul.wpuf-form li .wpuf-fields table.wpuf-repeatable-field * { +body ul.wpuf-form li .wpuf-fields .wpuf-repeatable-field.wpuf-field-columns { + display: flex; + justify-content: space-between; + align-items: center; +} +body ul.wpuf-form li .wpuf-fields .wpuf-repeatable-field .wpuf-column-field-inner-columns { + width: 100%; +} +body ul.wpuf-form li .wpuf-fields .wpuf-repeatable-field * { box-sizing: border-box; } -body ul.wpuf-form li .wpuf-fields table.wpuf-repeatable-field input { +body ul.wpuf-form li .wpuf-fields .wpuf-repeatable-field input { width: 100%; } -body ul.wpuf-form li .wpuf-fields table.wpuf-repeatable-field .wpuf-repeater-buttons { +body ul.wpuf-form li .wpuf-fields .wpuf-repeatable-field .wpuf-repeater-buttons { width: 75px; padding-left: 12px; } -body ul.wpuf-form li .wpuf-fields table.wpuf-repeatable-field .wpuf-repeater-buttons img { +body ul.wpuf-form li .wpuf-fields .wpuf-repeatable-field .wpuf-repeater-buttons img { width: 100%; height: auto; } -body ul.wpuf-form li .wpuf-fields table.wpuf-repeatable-field .wpuf-repeater-buttons i { +body ul.wpuf-form li .wpuf-fields .wpuf-repeatable-field .wpuf-repeater-buttons i { display: inline-block; width: 15px; height: 15px; @@ -945,9 +966,6 @@ body .pass-strength-result.strong { background-color: #c3ff88; border-color: #8dff1c !important; } -body .password[type="text"] { - display: none; -} body table.wpuf-table { border: 1px solid #E7E7E7; margin: 0 0px 10px 0; @@ -1096,16 +1114,30 @@ body fieldset.wpuf-multistep-fieldset { body fieldset.wpuf-multistep-fieldset.field-active { display: block; } -body fieldset.wpuf-multistep-fieldset .wpuf-multistep-prev-btn, -body fieldset.wpuf-multistep-fieldset .wpuf-multistep-next-btn { +body fieldset.wpuf-multistep-fieldset button.wpuf-multistep-next-btn.btn.btn-primary { + position: absolute; + bottom: 0; + right: 0; +} +body fieldset.wpuf-multistep-fieldset button.wpuf-multistep-prev-btn.btn.btn-primary { + position: absolute; + bottom: 0; + left: 0; +} +body fieldset.wpuf-multistep-fieldset a#wpuf-post-draft { position: absolute; - bottom: 5px; + bottom: 0; + right: calc(50% - 35px); } -body fieldset.wpuf-multistep-fieldset .wpuf-multistep-prev-btn { - left: 10px; +body fieldset.wpuf-multistep-fieldset span.wpuf-draft-saved { + position: absolute; + bottom: 0; + right: calc(50% - 150px); } -body fieldset.wpuf-multistep-fieldset .wpuf-multistep-next-btn { - right: 10px; +body fieldset.wpuf-multistep-fieldset span.wpuf-loading { + position: absolute; + bottom: 8px; + right: calc(50% - 60px); } body .wpuf-multistep-progressbar { overflow: hidden; @@ -1222,7 +1254,6 @@ body .wpuf-form .required { border: 0; } body .wpuf-dashboard-container { - font-family: 'Open Sans', sans-serif; max-width: 85rem !important; /*Responsive css for post table*/ } @@ -1238,7 +1269,6 @@ body .wpuf-dashboard-container .wpuf-dashboard-navigation { body .wpuf-dashboard-container .wpuf-dashboard-navigation a { text-decoration: none; box-shadow: none; - font-family: 'Open Sans', sans-serif; font-size: 16px; font-weight: bold; color: #000; @@ -1306,7 +1336,6 @@ body .wpuf-dashboard-container table.items-table { width: 100%; margin-top: 0px; border: 1.0218px solid #DAE1F5; - font-family: 'Open Sans', sans-serif !important; color: #000 !important; font-size: 16px !important; font-weight: 400 !important; @@ -1464,7 +1493,6 @@ body input[type="text"].wpuf-google-map-search { background-color: #fff !important; text-overflow: ellipsis !important; width: 170px !important; - font-family: Roboto !important; font-size: 15px !important; font-weight: 300 !important; padding: 0 11px 0 13px !important; @@ -1645,9 +1673,6 @@ body .weforms-quiz-feedback .wrong-answer .wpuf-fields label.checked { color: red; padding: 6px 0; } -body ul.wpuf-form .wpuf-el { - position: relative; -} body ul.wpuf-form .weforms-frontend-field-points { position: absolute; top: 0; diff --git a/assets/less/frontend-forms.less b/assets/less/frontend-forms.less index 935d8aefd..7f1e9cf44 100644 --- a/assets/less/frontend-forms.less +++ b/assets/less/frontend-forms.less @@ -5,7 +5,6 @@ @mediaMD: 1200px; /* DivTable.com */ body { - font-family: 'Open Sans', sans-serif; #wpfooter { position: fixed !important } @@ -212,6 +211,11 @@ body { } } + .wpuf-fields-inline { + display: flex; + justify-content: space-between; + } + .wpuf-submit{ input[type=submit] { @@ -258,7 +262,12 @@ ul.wpuf-form { border: 1px solid @borderColor; } - &.wpuf_hidden_field { + &wpuf-el { + position: relative; + display: flex; + } + + &.wpuf_hidden_field.wpuf-el { display: none; } @@ -388,7 +397,8 @@ ul.wpuf-form { } } - .wpuf-help { + .wpuf-help, + .wpuf-wordlimit-message { color: #666; margin: 2px 0 5px 0; font-size: 12px; @@ -555,6 +565,16 @@ ul.wpuf-form { .wpuf-repeatable-field { border-collapse: collapse; + &.wpuf-field-columns { + display: flex; + justify-content: space-between; + align-items: center; + } + + .wpuf-column-field-inner-columns { + width: 100%; + } + & * { box-sizing: border-box; } @@ -1041,10 +1061,6 @@ ul.wpuf_packs { } } -.password[type="text"]{ - display: none; -} - table.wpuf-table { border: 1px solid #E7E7E7; margin: 0 0px 10px 0; @@ -1213,16 +1229,33 @@ table.wpuf-table { display: block; } - .wpuf-multistep-prev-btn, - .wpuf-multistep-next-btn { + button.wpuf-multistep-next-btn.btn.btn-primary { + position: absolute; + bottom: 0; + right: 0; + } + + button.wpuf-multistep-prev-btn.btn.btn-primary { + position: absolute; + bottom: 0; + left: 0; + } + + a#wpuf-post-draft { position: absolute; - bottom: 5px; + bottom: 0; + right: ~"calc(50% - 35px)"; } - .wpuf-multistep-prev-btn { - left: 10px; + + span.wpuf-draft-saved { + position: absolute; + bottom: 0; + right: ~"calc(50% - 150px)"; } - .wpuf-multistep-next-btn { - right: 10px; + span.wpuf-loading { + position: absolute; + bottom: 8px; + right: ~"calc(50% - 60px)"; } } @@ -1375,7 +1408,6 @@ body.rtl{ } } .wpuf-dashboard-container { - font-family: 'Open Sans', sans-serif; max-width: 85rem !important; .clearfix(); .wpuf-dashboard-navigation { @@ -1385,7 +1417,6 @@ body.rtl{ a { text-decoration: none; box-shadow: none; - font-family: 'Open Sans', sans-serif; font-size: 16px; font-weight: bold; color: #000; @@ -1450,7 +1481,6 @@ body.rtl{ width: 100%; margin-top: 0px; border: 1.0218px solid #DAE1F5; - font-family: 'Open Sans', sans-serif !important; color: #000 !important; font-size: 16px !important; font-weight: 400 !important; @@ -1659,7 +1689,6 @@ input[type="text"].wpuf-google-map-search { background-color: #fff !important; text-overflow: ellipsis !important; width: 170px !important; - font-family: Roboto !important; font-size: 15px !important; font-weight: 300 !important; padding: 0 11px 0 13px !important; @@ -1890,10 +1919,6 @@ ul.wpuf-form .ui-state-default.wpuf-image-wrap .caption span:hover{ padding: 6px 0; } -ul.wpuf-form .wpuf-el{ - position: relative; -} - ul.wpuf-form .weforms-frontend-field-points{ position: absolute; top: 0; @@ -2050,38 +2075,6 @@ ul.wpuf-form{ } } } - .wpuf-repeatable-field{ - display: flex; - - &.has-columns-1{ - .wpuf-column{ - .wpuf-column-inner-fields{ - width: 90%; - } - } - } - - &.has-columns-2{ - .wpuf-column{ - .wpuf-column-inner-fields{ - width: 45%; - } - } - } - - &.has-columns-3{ - .wpuf-column{ - .wpuf-column-inner-fields{ - width: 30%; - } - } - } - - .wpuf-column-field-inner-columns{ - width: 90%; - } - - } } .ac_results { diff --git a/includes/class-frontend-form-post.php b/includes/class-frontend-form-post.php index 77fb624e0..5d3248bbb 100755 --- a/includes/class-frontend-form-post.php +++ b/includes/class-frontend-form-post.php @@ -734,7 +734,7 @@ public static function update_post_meta( $meta_vars, $post_id ) { // delete previous repeat values if ( ! empty( $repeat_fields ) ) { - $row_num = get_post_meta( $post_id, $repeat_fields['repeat_meta'], true ); + $row_num = get_post_meta( $post_id, $repeat_fields['repeat_meta'], true ); if ( $row_num ) { $sub_fields = ! empty( $repeat_fields['sub_fields'] ) ? $repeat_fields['sub_fields'] : []; @@ -766,8 +766,6 @@ public static function update_post_meta( $meta_vars, $post_id ) { } } - - // save all custom fields foreach ( $meta_key_value as $meta_key => $meta_value ) { update_post_meta( $post_id, $meta_key, $meta_value ); diff --git a/wpuf-functions.php b/wpuf-functions.php index 820702d8e..cb48968a7 100644 --- a/wpuf-functions.php +++ b/wpuf-functions.php @@ -874,7 +874,6 @@ function wpuf_show_custom_fields( $content ) { // get column field input fields if ( 'column_field' === $attr['input_type'] ) { $inner_fields = $attr['inner_fields']; - foreach ( $inner_fields as $column_key => $column_fields ) { if ( ! empty( $column_fields ) ) { // ignore section break and HTML input type @@ -891,6 +890,35 @@ function wpuf_show_custom_fields( $content ) { if ( isset( $attr['show_in_post'] ) && 'yes' === $attr['show_in_post'] ) { $meta[] = $attr; } + + // get repeat field inner fields + if ( 'repeat' === $attr['input_type'] ) { + $inner_fields = $attr['inner_fields']; + foreach ( $inner_fields as $column_key => $column_fields ) { + if ( ! empty( $column_fields ) ) { + // ignore section break and HTML input type + foreach ( $column_fields as $column_field_key => $column_field ) { + if ( isset( $column_field['show_in_post'] ) && 'yes' === $column_field['show_in_post'] ) { + $repeat_rows = get_post_meta( $post->ID, 'repeat_field', true ); + + if ( ! empty( $repeat_rows ) ) { + for ( $index = 0; $index < $repeat_rows; $index++ ) { + $field_value = get_post_meta( $post->ID, 'repeat_field_' . $index . '_' . $column_field['name'], true ); + $hide_label = ! empty( $column_field['hide_field_label'] ) ? $column_field['hide_field_label'] : 'no'; + $html .= '
  • '; + + if ( 'no' === $hide_label ) { + $html .= ''; + } + + $html .= make_clickable( $field_value ) . '
  • '; + } + } + } + } + } + } + } } if ( ! $meta ) { @@ -1084,7 +1112,7 @@ function wpuf_show_custom_fields( $content ) { $html .= $address_html; break; - case 'repeat': + case 'repeat_field': $value = get_post_meta( $post->ID, $attr['name'] ); $newvalue = []; @@ -4430,3 +4458,144 @@ function wpuf_get_image_sizes_array( $size = '' ) { } return $sizes; } + +/** + * The HTML preview part when hovering over a pro settings field + * + * @since 3.6.0 + * + * @return string + */ +function wpuf_get_pro_preview_html() { + $crown_icon = WPUF_ROOT . '/assets/images/crown.svg'; + return sprintf( '', esc_url( WPUF_Pro_Prompt::get_upgrade_to_pro_popup_url() ), '_blank', 'wpuf-button button-upgrade-to-pro', + file_get_contents( $crown_icon ) ); +} + +/** + * The HTML tooltip when hovering over a pro settings field + * + * @since 3.6.0 + * + * @return string + */ +function wpuf_get_pro_preview_tooltip() { + $crown_icon = WPUF_ROOT . '/assets/images/crown.svg'; + $check_icon = WPUF_ROOT . '/assets/images/check.svg'; + $features = [ + '24/7 Priority Support', + '20+ Premium Modules', + 'User Activity and Reports', + 'Private Messaging Option', + 'License for 20 websites', + ]; + $html = '
    '; + $html .= '

    Available in Pro. Also enjoy:

    '; + $html .= '
      '; + + foreach ( $features as $feature ) { + $html .= sprintf( + '
    • %1$s %2$s
    • ', + file_get_contents( $check_icon ), + esc_html( $feature ) + ); + } + + $html .= '
    '; + $html .= sprintf( '', + esc_url( WPUF_Pro_Prompt::get_upgrade_to_pro_popup_url() ), '_blank', 'wpuf-button button-upgrade-to-pro', + file_get_contents( $crown_icon ) ); + + $html .= ''; + $html .= '
    '; + + return $html; +} + +/** + * Get the shortcodes that are protected on the post form. + * User cannot submit post containing those shortcodes. + * + * @since 3.6.6 + * + * @return array + */ +function wpuf_get_protected_shortcodes() { + return [ + 'wpuf-registration', + ]; +} + +/** + * Get the current users roles as an array + * + * @since 3.6.6 + * + * @return array|bool + */ +function wpuf_get_single_user_roles( $user_id ) { + if ( ! is_numeric( $user_id ) ) { + return false; + } + + $user = get_user_by( 'id', $user_id ); + + if ( ! $user ) { + return false; + } + + return ( array ) $user->roles; +} + +/** + * Check and modify the post content not to render shortcode values + * in the frontend for any user except admin. + * + * @since 3.6.6 + * + * @return string + */ +function wpuf_modify_shortcodes( $content ) { + global $pagenow; + + if ( 'post.php' === $pagenow ) { + return $content; + } + + // get the id of the user who last edited the post + $user_id = get_post_meta( get_post()->ID, '_edit_last', true ); + + $roles = wpuf_get_single_user_roles( $user_id ); + + if ( empty( $roles ) ) { + return $content; + } + + // last modified by an admin, returns the content as it is + if ( in_array( 'administrator', $roles ) ) { + return $content; + } + + $protected_shortcodes = wpuf_get_protected_shortcodes(); + + foreach ( $protected_shortcodes as $shortcode ) { + $search_for = '[' . $shortcode; + + if ( strpos( $content, $search_for ) !== false ) { + $pattern = '/\[' . $shortcode . '(.*?)\]/'; + + $content = preg_replace_callback( + $pattern, function( $matches ) { + return str_replace( [ '[', ']' ], [ '[', ']' ], $matches[0] ); + }, $content + ); + } + } + + return $content; +} + +// @todo: move this to frontend class +add_filter( 'the_content', 'wpuf_modify_shortcodes' ); From 696eb91c7cea095c6595ea637508a5663e5aa009 Mon Sep 17 00:00:00 2001 From: Sapayth Hossain Date: Wed, 13 Sep 2023 15:10:46 +0600 Subject: [PATCH 09/20] prevent modifying meta key --- .../js/components/form-column_field/index.js | 4 ++-- admin/form-builder/assets/js/form-builder.js | 5 +++++ .../class-wpuf-admin-form-builder-ajax.php | 1 - .../form-builder/class-wpuf-admin-form-builder.php | 14 ++++++++++++++ assets/js/wpuf-form-builder-components.js | 4 ++-- assets/js/wpuf-form-builder.js | 5 +++++ includes/fields/class-field-textarea.php | 4 ++++ 7 files changed, 32 insertions(+), 5 deletions(-) diff --git a/admin/form-builder/assets/js/components/form-column_field/index.js b/admin/form-builder/assets/js/components/form-column_field/index.js index 4eb9c26f6..cae279071 100644 --- a/admin/form-builder/assets/js/components/form-column_field/index.js +++ b/admin/form-builder/assets/js/components/form-column_field/index.js @@ -162,7 +162,7 @@ Vue.component('form-column_field', { return ( field.recaptcha_type && 'invisible_recaptcha' === field.recaptcha_type ) ? true : false; }, - isAllowedInClolumnField: function(field_template) { + isAllowedInColumnField: function(field_template) { var restrictedFields = ['column_field', 'custom_hidden_field', 'step_start']; if ( $.inArray(field_template, restrictedFields) >= 0 ) { @@ -180,7 +180,7 @@ Vue.component('form-column_field', { toWhichColumn: data.to_column }; - if (this.isAllowedInClolumnField(data.field_template)) { + if (this.isAllowedInColumnField(data.field_template)) { swal({ title: "Oops...", text: "You cannot add this field as inner column field" diff --git a/admin/form-builder/assets/js/form-builder.js b/admin/form-builder/assets/js/form-builder.js index e49adeb94..d33959e6d 100644 --- a/admin/form-builder/assets/js/form-builder.js +++ b/admin/form-builder/assets/js/form-builder.js @@ -138,6 +138,11 @@ var columnFieldIndex = 0; while (columnFieldIndex < innerColumnFields[columnFields].length) { + // don't modify existing meta key + if (payload.field_name === 'name' && ! innerColumnFields[columnFields][columnFieldIndex].hasOwnProperty('is_new') ) { + break; + } + if (innerColumnFields[columnFields][columnFieldIndex].id === parseInt(payload.editing_field_id)) { innerColumnFields[columnFields][columnFieldIndex][payload.field_name] = payload.value; } diff --git a/admin/form-builder/class-wpuf-admin-form-builder-ajax.php b/admin/form-builder/class-wpuf-admin-form-builder-ajax.php index 82c15d74e..dc1d9c4d0 100644 --- a/admin/form-builder/class-wpuf-admin-form-builder-ajax.php +++ b/admin/form-builder/class-wpuf-admin-form-builder-ajax.php @@ -54,7 +54,6 @@ public function save_form() { $integrations = (array) json_decode( $post_data['integrations'] ); } - $form_fields = json_decode( $form_fields, true ); $notifications = json_decode( $notifications, true ); diff --git a/admin/form-builder/class-wpuf-admin-form-builder.php b/admin/form-builder/class-wpuf-admin-form-builder.php index 8093a1d0d..ad40a61c8 100644 --- a/admin/form-builder/class-wpuf-admin-form-builder.php +++ b/admin/form-builder/class-wpuf-admin-form-builder.php @@ -336,6 +336,20 @@ public static function save_form( $data ) { $field_id = $field['id']; } + // for column and repeat fields, remove unwanted properties from inner fields + if ( ! empty( $field['inner_fields'] ) ) { + foreach ( $field['inner_fields'] as $column => $inner_field ) { + foreach ( $inner_field as $index => $single_field ) { + if ( ! empty( $single_field['is_new'] ) ) { + unset( $field['inner_fields'][ $column ][ $index ]['is_new'] ); + unset( $field['inner_fields'][ $column ][ $index ]['id'] ); + + $field['inner_fields'][ $column ][ $index ]['id'] = 0; + } + } + } + } + $field_id = wpuf_insert_form_field( $data['form_id'], $field, $field_id, $order ); $new_wpuf_input_ids[] = $field_id; diff --git a/assets/js/wpuf-form-builder-components.js b/assets/js/wpuf-form-builder-components.js index 672a9b3e4..8292b7182 100644 --- a/assets/js/wpuf-form-builder-components.js +++ b/assets/js/wpuf-form-builder-components.js @@ -926,7 +926,7 @@ Vue.component('form-column_field', { return ( field.recaptcha_type && 'invisible_recaptcha' === field.recaptcha_type ) ? true : false; }, - isAllowedInClolumnField: function(field_template) { + isAllowedInColumnField: function(field_template) { var restrictedFields = ['column_field', 'custom_hidden_field', 'step_start']; if ( $.inArray(field_template, restrictedFields) >= 0 ) { @@ -944,7 +944,7 @@ Vue.component('form-column_field', { toWhichColumn: data.to_column }; - if (this.isAllowedInClolumnField(data.field_template)) { + if (this.isAllowedInColumnField(data.field_template)) { swal({ title: "Oops...", text: "You cannot add this field as inner column field" diff --git a/assets/js/wpuf-form-builder.js b/assets/js/wpuf-form-builder.js index e49adeb94..d33959e6d 100644 --- a/assets/js/wpuf-form-builder.js +++ b/assets/js/wpuf-form-builder.js @@ -138,6 +138,11 @@ var columnFieldIndex = 0; while (columnFieldIndex < innerColumnFields[columnFields].length) { + // don't modify existing meta key + if (payload.field_name === 'name' && ! innerColumnFields[columnFields][columnFieldIndex].hasOwnProperty('is_new') ) { + break; + } + if (innerColumnFields[columnFields][columnFieldIndex].id === parseInt(payload.editing_field_id)) { innerColumnFields[columnFields][columnFieldIndex][payload.field_name] = payload.value; } diff --git a/includes/fields/class-field-textarea.php b/includes/fields/class-field-textarea.php index 6c49e2a28..61cb0007d 100755 --- a/includes/fields/class-field-textarea.php +++ b/includes/fields/class-field-textarea.php @@ -161,6 +161,10 @@ public function prepare_entry( $field ) { * @return string */ public function render_field_data( $data, $field ) { + if ( ! is_string( $data ) ) { + return ''; + } + $data = implode( ',', $data ); $hide_label = isset( $field['hide_field_label'] ) ? wpuf_validate_boolean( $field['hide_field_label'] ) From dccd63b237e2a3c97b77a4a766c91b2ae661610f Mon Sep 17 00:00:00 2001 From: Sapayth Hossain Date: Wed, 13 Sep 2023 15:36:58 +0600 Subject: [PATCH 10/20] restore calling list() function as previous --- includes/class-frontend-form-post.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/class-frontend-form-post.php b/includes/class-frontend-form-post.php index 9b4a0f50b..d415af377 100755 --- a/includes/class-frontend-form-post.php +++ b/includes/class-frontend-form-post.php @@ -707,7 +707,7 @@ public function add_post_shortcode( $atts ) { $this->form_fields = $form->get_fields(); $this->form_settings = $form->get_settings(); $this->generate_auth_link(); // Translate tag %login% %registration% to login registartion url - list( $user_can_post, $info ) = $form->is_submission_open( $form, $this->form_settings ); + [ $user_can_post, $info ] = $form->is_submission_open( $form, $this->form_settings ); $info = apply_filters( 'wpuf_addpost_notice', $info, $id, $this->form_settings ); $user_can_post = apply_filters( 'wpuf_can_post', $user_can_post, $id, $this->form_settings ); @@ -725,7 +725,7 @@ public function add_post_shortcode( $atts ) { public static function update_post_meta( $meta_vars, $post_id ) { // check_ajax_referer( 'wpuf_form_add' ); // prepare the meta vars - list( $meta_key_value, $repeat_fields, $files ) = self::prepare_meta_fields( $meta_vars ); + [ $meta_key_value, $multi_repeated, $files ] = self::prepare_meta_fields( $meta_vars ); // set featured image if there's any // @codingStandardsIgnoreStart @@ -894,7 +894,7 @@ public function prepare_mail_body( $content, $user_id, $post_id ) { // custom fields preg_match_all( '/%custom_([\w-]*)\b%/', $content, $matches ); - list( $search, $replace ) = $matches; + [ $search, $replace ] = $matches; if ( $replace ) { foreach ( $replace as $index => $meta_key ) { From 52c6aed17c8809d567192e8eaa5aa37eee0f2cb2 Mon Sep 17 00:00:00 2001 From: Sapayth Hossain Date: Thu, 14 Sep 2023 12:07:51 +0600 Subject: [PATCH 11/20] fix typo --- .../assets/js/components/form-column_field/index.js | 3 ++- assets/js/wpuf-form-builder-components.js | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/admin/form-builder/assets/js/components/form-column_field/index.js b/admin/form-builder/assets/js/components/form-column_field/index.js index 90a1f7cd9..6c17f423e 100644 --- a/admin/form-builder/assets/js/components/form-column_field/index.js +++ b/admin/form-builder/assets/js/components/form-column_field/index.js @@ -162,6 +162,7 @@ Vue.component('form-column_field', { return ( field.recaptcha_type && 'invisible_recaptcha' === field.recaptcha_type ) ? true : false; }, + isAllowedInColumnField: function(field_template) { var restrictedFields = ['column_field', 'custom_hidden_field', 'step_start']; @@ -180,7 +181,7 @@ Vue.component('form-column_field', { toWhichColumn: data.to_column }; - if (this.isAllowedInClolumnField(data.field_template)) { + if (this.isAllowedInColumnField(data.field_template)) { Swal.fire({ title: "Oops...", text: "You cannot add this field as inner column field" diff --git a/assets/js/wpuf-form-builder-components.js b/assets/js/wpuf-form-builder-components.js index 75a13c4ff..8675ee6c0 100644 --- a/assets/js/wpuf-form-builder-components.js +++ b/assets/js/wpuf-form-builder-components.js @@ -928,6 +928,7 @@ Vue.component('form-column_field', { return ( field.recaptcha_type && 'invisible_recaptcha' === field.recaptcha_type ) ? true : false; }, + isAllowedInColumnField: function(field_template) { var restrictedFields = ['column_field', 'custom_hidden_field', 'step_start']; @@ -946,7 +947,7 @@ Vue.component('form-column_field', { toWhichColumn: data.to_column }; - if (this.isAllowedInClolumnField(data.field_template)) { + if (this.isAllowedInColumnField(data.field_template)) { Swal.fire({ title: "Oops...", text: "You cannot add this field as inner column field" From 4152b57a66893c47d6aeb6f427cf30d9f1c4a4fe Mon Sep 17 00:00:00 2001 From: Sapayth Hossain Date: Thu, 14 Sep 2023 13:53:20 +0600 Subject: [PATCH 12/20] fix editing inner field --- admin/form-builder/class-wpuf-admin-form-builder.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/admin/form-builder/class-wpuf-admin-form-builder.php b/admin/form-builder/class-wpuf-admin-form-builder.php index 20d2531dc..0f77eee89 100644 --- a/admin/form-builder/class-wpuf-admin-form-builder.php +++ b/admin/form-builder/class-wpuf-admin-form-builder.php @@ -340,9 +340,6 @@ public static function save_form( $data ) { foreach ( $inner_field as $index => $single_field ) { if ( ! empty( $single_field['is_new'] ) ) { unset( $field['inner_fields'][ $column ][ $index ]['is_new'] ); - unset( $field['inner_fields'][ $column ][ $index ]['id'] ); - - $field['inner_fields'][ $column ][ $index ]['id'] = 0; } } } From f2eff9865becb1f3c418eb26d78f2036d5d2d875 Mon Sep 17 00:00:00 2001 From: Sapayth Hossain Date: Thu, 14 Sep 2023 15:55:29 +0600 Subject: [PATCH 13/20] nested checkbox check added --- includes/fields/class-field-checkbox.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/includes/fields/class-field-checkbox.php b/includes/fields/class-field-checkbox.php index a4a54288f..62b5a9bf2 100755 --- a/includes/fields/class-field-checkbox.php +++ b/includes/fields/class-field-checkbox.php @@ -187,8 +187,10 @@ public function render_field_data( $data, $field ) { return; } + $data = is_array( $data ) ? array_pop( $data ) : $data; + // check again if there is any nested data $data = is_array( $data ) ? array_pop( $data ) : $data; - $data = explode( '|' , $data ); + $data = explode( '|', $data ); $selected = []; foreach ( $data as $item ) { From c29da158bf3d76a51c696ba32d709a4a83e56db6 Mon Sep 17 00:00:00 2001 From: Sapayth Hossain Date: Fri, 29 Sep 2023 15:48:34 +0600 Subject: [PATCH 14/20] repeat text field --- wpuf-functions.php | 27 ++++----------------------- 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/wpuf-functions.php b/wpuf-functions.php index cf217f527..b48ed4b47 100644 --- a/wpuf-functions.php +++ b/wpuf-functions.php @@ -918,11 +918,12 @@ function wpuf_show_custom_fields( $content ) { // ignore section break and HTML input type foreach ( $column_fields as $column_field_key => $column_field ) { if ( isset( $column_field['show_in_post'] ) && 'yes' === $column_field['show_in_post'] ) { - $repeat_rows = get_post_meta( $post->ID, 'repeat_field', true ); + $repeat_field_name = ! empty( $attr['name'] ) ? $attr['name'] : ''; + $repeat_rows = get_post_meta( $post->ID, $repeat_field_name, true ); if ( ! empty( $repeat_rows ) ) { for ( $index = 0; $index < $repeat_rows; $index++ ) { - $field_value = get_post_meta( $post->ID, 'repeat_field_' . $index . '_' . $column_field['name'], true ); + $field_value = get_post_meta( $post->ID, $repeat_field_name . '_' . $index . '_' . $column_field['name'], true ); $hide_label = ! empty( $column_field['hide_field_label'] ) ? $column_field['hide_field_label'] : 'no'; $html .= '
  • '; @@ -1131,27 +1132,7 @@ function wpuf_show_custom_fields( $content ) { $html .= $address_html; break; - case 'repeat_field': - $value = get_post_meta( $post->ID, $attr['name'] ); - $newvalue = []; - - foreach ( $value as $i => $str ) { - if ( preg_match( '/[^\|\s]/', $str ) ) { - $newvalue[] = $str; - } - } - - $new = implode( ', ', $newvalue ); - - if ( $new ) { - $html .= '
  • '; - - if ( 'no' === $hide_label ) { - $html .= ''; - } - - $html .= make_clickable( $new ) . '
  • '; - } + case 'repeat': break; case 'url': From 9e7fe7ed3164b9e28ee201c6eb084e7e9d198126 Mon Sep 17 00:00:00 2001 From: Sapayth Hossain Date: Fri, 29 Sep 2023 17:20:42 +0600 Subject: [PATCH 15/20] fix: meta key modification for inner fields --- admin/form-builder/assets/js/form-builder.js | 3 ++- assets/js/wpuf-form-builder.js | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/admin/form-builder/assets/js/form-builder.js b/admin/form-builder/assets/js/form-builder.js index bf8b910fa..90eaa93c6 100644 --- a/admin/form-builder/assets/js/form-builder.js +++ b/admin/form-builder/assets/js/form-builder.js @@ -140,7 +140,8 @@ while (columnFieldIndex < innerColumnFields[columnFields].length) { // don't modify existing meta key if (payload.field_name === 'name' && ! innerColumnFields[columnFields][columnFieldIndex].hasOwnProperty('is_new') ) { - break; + columnFieldIndex++; + continue; } if (innerColumnFields[columnFields][columnFieldIndex].id === parseInt(payload.editing_field_id)) { diff --git a/assets/js/wpuf-form-builder.js b/assets/js/wpuf-form-builder.js index bf8b910fa..90eaa93c6 100644 --- a/assets/js/wpuf-form-builder.js +++ b/assets/js/wpuf-form-builder.js @@ -140,7 +140,8 @@ while (columnFieldIndex < innerColumnFields[columnFields].length) { // don't modify existing meta key if (payload.field_name === 'name' && ! innerColumnFields[columnFields][columnFieldIndex].hasOwnProperty('is_new') ) { - break; + columnFieldIndex++; + continue; } if (innerColumnFields[columnFields][columnFieldIndex].id === parseInt(payload.editing_field_id)) { From a48eda23484f58db642b251a2a6473d038c9106d Mon Sep 17 00:00:00 2001 From: Sapayth Hossain Date: Mon, 27 Nov 2023 00:47:44 +0600 Subject: [PATCH 16/20] fix: radio field --- assets/css/frontend-forms.css | 3 --- assets/js/frontend-form.js | 6 +++--- assets/less/frontend-forms.less | 4 ---- includes/class-frontend-form-post.php | 13 +++++-------- includes/fields/class-field-checkbox.php | 1 + includes/fields/class-field-radio.php | 1 + 6 files changed, 10 insertions(+), 18 deletions(-) diff --git a/assets/css/frontend-forms.css b/assets/css/frontend-forms.css index 982cc4f72..a194effb5 100644 --- a/assets/css/frontend-forms.css +++ b/assets/css/frontend-forms.css @@ -518,9 +518,6 @@ body ul.wpuf-form li .wpuf-fields .wpuf-repeatable-field .wpuf-column-field-inne body ul.wpuf-form li .wpuf-fields .wpuf-repeatable-field * { box-sizing: border-box; } -body ul.wpuf-form li .wpuf-fields .wpuf-repeatable-field input { - width: 100%; -} body ul.wpuf-form li .wpuf-fields .wpuf-repeatable-field .wpuf-repeater-buttons { width: 75px; padding-left: 12px; diff --git a/assets/js/frontend-form.js b/assets/js/frontend-form.js index f223704e4..70a7c994a 100644 --- a/assets/js/frontend-form.js +++ b/assets/js/frontend-form.js @@ -354,11 +354,11 @@ //clear the inputs clone.find( 'input' ).val( '' ); clone.find( 'textarea' ).val( '' ); - clone.find( ':checked' ).attr( 'checked', '' ); - div.after( clone ); - + clone.find( ':checked' ).prop( 'checked', false ); WP_User_Frontend.calculateFieldsName( $( this ).parents( '.wpuf-field-columns' ) ); WP_User_Frontend.setRowNumber( $( this ).closest( '.wpuf-field-columns' ) ); + + div.after( clone ); }, removeRepeatField: function () { diff --git a/assets/less/frontend-forms.less b/assets/less/frontend-forms.less index 7f1e9cf44..89b31188c 100644 --- a/assets/less/frontend-forms.less +++ b/assets/less/frontend-forms.less @@ -579,10 +579,6 @@ ul.wpuf-form { box-sizing: border-box; } - input { - width: 100%; - } - .wpuf-repeater-buttons { width: 75px; padding-left: 12px; diff --git a/includes/class-frontend-form-post.php b/includes/class-frontend-form-post.php index d415af377..5cc7c0f28 100755 --- a/includes/class-frontend-form-post.php +++ b/includes/class-frontend-form-post.php @@ -773,15 +773,12 @@ public static function update_post_meta( $meta_vars, $post_id ) { if ( ! empty( $repeat_fields ) ) { if ( ! empty( $meta_key_value[ $repeat_fields['repeat_meta'] ] ) ) { $row_number = $meta_key_value[ $repeat_fields['repeat_meta'] ]; + $sub_fields = ! empty( $repeat_fields['sub_fields'] ) ? $repeat_fields['sub_fields'] : []; - if ( ! empty( $row_number ) ) { - $sub_fields = ! empty( $repeat_fields['sub_fields'] ) ? $repeat_fields['sub_fields'] : []; - - for ( $i = 0; $i < $row_num; $i++ ) { - foreach ( $sub_fields as $value ) { - $field_meta = $repeat_fields['repeat_meta'] . '_' . $i . '_' . $value; - update_post_meta( $post_id, '_' . $field_meta, uniqid( 'field_' ) ); - } + for ( $i = 0; $i < $row_number; $i++ ) { + foreach ( $sub_fields as $value ) { + $field_meta = $repeat_fields['repeat_meta'] . '_' . $i . '_' . $value; + update_post_meta( $post_id, '_' . $field_meta, uniqid( 'field_' ) ); } } } diff --git a/includes/fields/class-field-checkbox.php b/includes/fields/class-field-checkbox.php index 62b5a9bf2..f30e9947e 100755 --- a/includes/fields/class-field-checkbox.php +++ b/includes/fields/class-field-checkbox.php @@ -44,6 +44,7 @@ public function render( $field_settings, $form_id, $type = 'post', $post_id = nu data-required="" diff --git a/includes/fields/class-field-radio.php b/includes/fields/class-field-radio.php index d81ef1d72..d29307c71 100755 --- a/includes/fields/class-field-radio.php +++ b/includes/fields/class-field-radio.php @@ -48,6 +48,7 @@ public function render( $field_settings, $form_id, $type = 'post', $post_id = nu