diff --git a/assets/css/admin.scss b/assets/css/admin.scss index 6562a9cbf..ffd3910f9 100644 --- a/assets/css/admin.scss +++ b/assets/css/admin.scss @@ -2118,7 +2118,32 @@ body { display: none; } } - + .ur-advance-setting-group { + border: 1px solid #f0f0f0; + padding: 0.25rem; + position: relative; + display: flex; + align-items: center; + margin-bottom: 1rem; + &.row { + align-items: end; + } + &.column { + flex-direction: column; + } + .ur-legend { + font-weight: 100; + font-size: 0.9rem; + position: absolute; + top: -10px; + left: 10px; + color: #333; + background-color: white; + } + label { + font-size: 0.75rem !important; + } + } .ur-advance-setting-block { margin-top: 0; } diff --git a/assets/css/user-registration.scss b/assets/css/user-registration.scss index 48965102b..6fda0cb88 100644 --- a/assets/css/user-registration.scss +++ b/assets/css/user-registration.scss @@ -3106,3 +3106,6 @@ body.user-registration-page { animation: toaster 5s ease-in-out forwards; } +.user-registration.ur-frontend-form form.register .d-none { + display: none; +} \ No newline at end of file diff --git a/assets/js/admin/form-builder.js b/assets/js/admin/form-builder.js index 6249fa2ef..5bf835b04 100644 --- a/assets/js/admin/form-builder.js +++ b/assets/js/admin/form-builder.js @@ -256,6 +256,79 @@ } } ); + + + // Hide sublabels from ur field in case of multiple fields field. + $(document).on('change', '#ur-setting-form [data-field=hide_sublabels]', function() { + if ($(this).is(':checked')) { + $('.ur-input-grids').find('.ur-item-active .ur-field').find('label').addClass('ur-d-none'); + } else { + $('.ur-input-grids').find('.ur-item-active .ur-field').find('label').removeClass('ur-d-none'); + } + }); + + // Hide sublabels from ur field in case of multiple fields field. + $(document).on('change', '#ur-setting-form [data-field=hide_sublabels]', function() { + if ($(this).is(':checked')) { + $('.ur-input-grids').find('.ur-item-active .ur-field').find('label').addClass('ur-d-none'); + } else { + $('.ur-input-grids').find('.ur-item-active .ur-field').find('label').removeClass('ur-d-none'); + } + }); + + // update placeholder for each sub fields. + var sourceInput = '.ur-advance-setting-group [data-advance-field$="placeholder"]'; + $(document).on('input', sourceInput, function () { + var targetInput = '.ur-' + $(this).data('advance-field').replace(/_placeholder$/, '').replace(/_/g, '-') + ' input'; + var inputValue = $(this).val(); + $(targetInput).attr('placeholder', inputValue); + }); + + + // show/hide sub fields. + $('.ur-advance-setting-group input[type="checkbox"]').each(function() { + var forClass = $(this).is(':checked'); + if($(this).is(":checked")) { + $('.ur-input-grids .ur-item-active').find('.' + forClass).addClass('ur-d-none'); + } else { + $('.ur-input-grids .ur-item-active').find('.' + forClass).removeClass('ur-d-none'); + } + }); + $(document).on('change', '.ur-advance-setting-group input[type="checkbox"]', function() { + var forClass = $(this).data('id'); + if($(this).is(":checked")) { + $('.ur-input-grids .ur-item-active').find('.' + forClass).addClass('ur-d-none'); + } else { + $('.ur-input-grids .ur-item-active').find('.' + forClass).removeClass('ur-d-none'); + } + }); + + // update placeholder for each sub fields. + let sourceInput = '.ur-advance-setting-group [data-advance-field$="placeholder"]'; + $(document).on('input', sourceInput, function () { + let targetInput = '.ur-' + $(this).data('advance-field').replace(/_placeholder$/, '').replace(/_/g, '-') + ' input'; + let inputValue = $(this).val(); + $(targetInput).attr('placeholder', inputValue); + }); + + + // show/hide sub fields. + $('.ur-advance-setting-group input[type="checkbox"]').each(function() { + let forClass = $(this).is(':checked'); + if($(this).is(":checked")) { + $('.ur-input-grids .ur-item-active').find('.' + forClass).addClass('ur-d-none'); + } else { + $('.ur-input-grids .ur-item-active').find('.' + forClass).removeClass('ur-d-none'); + } + }); + $(document).on('change', '.ur-advance-setting-group input[type="checkbox"]', function() { + let forClass = $(this).data('id'); + if($(this).is(":checked")) { + $('.ur-input-grids .ur-item-active').find('.' + forClass).addClass('ur-d-none'); + } else { + $('.ur-input-grids .ur-item-active').find('.' + forClass).removeClass('ur-d-none'); + } + }); }, init_user_profile_modal: function () { var user_profile_modal = { @@ -2213,7 +2286,9 @@ switch ($this_node.attr("type")) { case "checkbox": value = $this_node.is(":checked"); - + if ($this_node.data('field') == 'hide_sublabels') { + value = $(document).find('[data-field="hide_sublabels"]').prop('checked'); + } if ( $this_node.hasClass( "ur-type-checkbox-value" diff --git a/includes/abstracts/abstract-ur-field-settings.php b/includes/abstracts/abstract-ur-field-settings.php index 94b6bf7f5..2b735ea58 100644 --- a/includes/abstracts/abstract-ur-field-settings.php +++ b/includes/abstracts/abstract-ur-field-settings.php @@ -89,7 +89,18 @@ public function render_html($fields) foreach ($fields as $field_key => $field) { - $tooltip_html = ! empty($field['tip']) ? ur_help_tip($field['tip'], false, 'ur-portal-tooltip') : ''; + $tooltip_html = ! empty( $field['tip'] ) ? ur_help_tip( $field['tip'], false, 'ur-portal-tooltip' ) : ''; + + if( "row" === $field[ 'type' ] ) { + $this->fields_html .= '
'; + $this->fields_html .= '
' . $field['label'] . $tooltip_html . '
'; + $fields_html = $this->fields_html; + $this->render_html( $field['items'] ); + $this->fields_html = $fields_html . $this->fields_html; + $this->fields_html .= '
'; + continue; + } + $smart_tags = ''; if ('default_value' === $field_key) { /** diff --git a/includes/admin/class-ur-admin-menus.php b/includes/admin/class-ur-admin-menus.php index b362a4477..293316517 100644 --- a/includes/admin/class-ur-admin-menus.php +++ b/includes/admin/class-ur-admin-menus.php @@ -77,6 +77,16 @@ public function add_upgradable_other_fields() { 'video_id' => 'pzhJ3qjQfC4', 'name' => __( 'User Registration - File Upload', 'user-registration' ), ), + array( + 'id' => 'user_registration_address', + 'slug' => 'address', + 'label' => 'Address', + 'video_id' => 'CF_o-xrMXZM', + 'plan' => 'Personal Plan', + 'icon' => 'ur-icon ur-icon-flag', + 'name' => __( 'User Registration Pro', 'user-registration' ), + 'field_class' => 'UR_Form_Field_Address', + ), array( 'id' => 'user_registration_invite_code', 'label' => 'Invitation Code', diff --git a/includes/admin/settings/class-ur-users-menu.php b/includes/admin/settings/class-ur-users-menu.php index 6b97e0a4b..ff11108e4 100644 --- a/includes/admin/settings/class-ur-users-menu.php +++ b/includes/admin/settings/class-ur-users-menu.php @@ -955,7 +955,36 @@ private function render_user_form_fields($user_id) } elseif('membership' === $field_key){ $membership_id = get_user_meta($user->ID, 'user_registration_' . $field_name, true); $value = get_the_title($membership_id); - } else { + } elseif( 'address' === $field_key ) { + $address = (array)$user_metadata_details; + $address_parts = []; + if ( is_array( $address ) ) { + if ( ! empty( $address['address_line_1'] ) ) { + $address_parts[] = $address['address_line_1']; + } + if ( ! empty( $address['address_line_2'] ) ) { + $address_parts[] = $address['address_line_2']; + } + if ( ! empty( $address['city'] ) ) { + $address_parts[] = $address['city']; + } + if ( ! empty( $address['state'] ) ) { + $address_parts[] = $address['state']; + } + if ( ! empty( $address['zip_code'] ) ) { + $address_parts[] = $address['zip_code']; + } + if ( ! empty( $address['country'] ) ) { + $country_class = ur_load_form_field_class( 'country' ); + $countries = $country_class::get_instance()->get_country(); + $country_name = isset( $countries[ $address['country'] ] ) ? $countries[ $address['country'] ] : $address['country']; + $address_parts[] = $country_name; + } + $value = implode( ', ', $address_parts ); + } else { + $value = ''; + } + } else { $value = get_user_meta($user->ID, 'user_registration_' . $field_name, true); // For Woocommerce fields. diff --git a/includes/functions-ur-core.php b/includes/functions-ur-core.php index 414f1c1d1..c1fa27390 100644 --- a/includes/functions-ur-core.php +++ b/includes/functions-ur-core.php @@ -515,6 +515,9 @@ function ur_get_field_type( $field_key ) { case 'country': $field_type = 'select'; break; + case 'address': + $field_type = 'composite'; + break; case 'file': $field_type = 'file'; break; @@ -833,6 +836,7 @@ function ur_get_registered_form_fields() { 'checkbox', 'privacy_policy', 'radio', + 'address', ) ); } @@ -2737,13 +2741,24 @@ function ur_parse_name_values_for_smart_tags( $user_id, $form_id, $valid_form_da if ( isset( $form_data->field_type ) && 'repeater' === $form_data->field_type ) { $data_html .= '' . $value . ''; - } elseif ( isset( $form_data->extra_params['field_key'] ) && 'signature' === $form_data->extra_params['field_key'] ) { + } elseif ( isset( $form_data->field_type ) && 'address' === $form_data->field_type ) { + $data_html .= '' . json_encode( $value ) . ''; + } + elseif ( isset( $form_data->extra_params['field_key'] ) && 'signature' === $form_data->extra_params['field_key'] ) { $data_html .= '' . $label . ' : Signature'; } else { $data_html .= '' . $label . ' : ' . $value . ''; } - - $name_value[ $field_name ] = $value; + if( isset( $form_data->field_type ) && 'address' === $form_data->field_type ) { + $name_value[ $field_name ] = json_encode( $value ); + } else { + $name_value[ $field_name ] = $value; + } + if( isset( $form_data->field_type ) && 'address' === $form_data->field_type ) { + $name_value[ $field_name ] = json_encode( $value ); + } else { + $name_value[ $field_name ] = $value; + } } $data_html .= ''; @@ -5621,6 +5636,7 @@ function user_registration_validate_form_field_data( $data, $form_data, $form_id if ( ! empty( $validations ) ) { if ( in_array( 'required', $validations, true ) || ! empty( $single_field_value ) ) { + $single_field_value = $single_field_value instanceof stdClass ? (array) $single_field_value : $single_field_value; foreach ( $validations as $validation ) { $result = UR_Form_Validation::$validation( $single_field_value ); diff --git a/includes/validation/class-ur-form-validation.php b/includes/validation/class-ur-form-validation.php index 00e8711cf..b225ce39e 100644 --- a/includes/validation/class-ur-form-validation.php +++ b/includes/validation/class-ur-form-validation.php @@ -716,6 +716,7 @@ public function get_update_profile_validation_skippable_fields( $form_data ) { 'signature', 'membership', 'subscription_plan', + 'address', ); $form_skippable_fields = array_filter(