diff --git a/assets/css/admin.scss b/assets/css/admin.scss index 712347730..6208a09c7 100644 --- a/assets/css/admin.scss +++ b/assets/css/admin.scss @@ -3172,11 +3172,11 @@ body { box-shadow: inset 0 1px 2px rgba(35, 40, 45, 0.1); } - .ur-advance-setting.ur-advance-default_value, .ur-general-setting.ur-general-setting-hidden-value { + .ur-advance-setting.ur-advance-default_value, .ur-general-setting.ur-general-setting-hidden-value, .ur-advance-setting.ur-advance-pattern_value { position: relative; margin-bottom: 15px; - & input.ur_advance_setting.ur-settings-default-value, & input.ur-general-setting-field { + & input.ur_advance_setting.ur-settings-default-value, & input.ur-general-setting-field, & input.ur_advance_setting.ur-settings-pattern_value { width: calc(100% - 40px) !important; min-height: 27px; } diff --git a/assets/js/admin/form-builder.js b/assets/js/admin/form-builder.js index 37bf96ff1..acfd76442 100644 --- a/assets/js/admin/form-builder.js +++ b/assets/js/admin/form-builder.js @@ -3467,6 +3467,30 @@ .toggle(); }); break; + case "enable_pattern" : + if (!$this_node.is(":checked")) { + $(this) + .closest(".ur-advance-setting-block") + .find(".ur-advance-pattern_value") + .hide(); + $(this) + .closest(".ur-advance-setting-block") + .find(".ur-advance-pattern_message") + .hide(); + } + + $this_node.on("change", function () { + $(this) + .closest(".ur-advance-setting-block") + .find(".ur-advance-pattern_value") + .toggle(); + + $(this) + .closest(".ur-advance-setting-block") + .find(".ur-advance-pattern_message") + .toggle(); + }); + break; } var node_type = $this_node.get(0).tagName.toLowerCase(); @@ -4460,8 +4484,12 @@ .find("input") .val(); smart_tag = $(this).data("key"); - input_value += smart_tag; - update_input(input_value); + input_value = smart_tag; + var inputElement = $(this).parent().parent().parent().find("input"), + advanceFieldData = inputElement.data("advance-field"), + fieldData = inputElement.data("field"), + field_name = advanceFieldData !== undefined ? advanceFieldData : fieldData; + update_input(field_name,input_value); $(this).parent().parent().parent().find("input").val(input_value); $(document.body).find(".ur-smart-tags-list").hide(); @@ -4472,6 +4500,7 @@ ".ur_advance_setting.ur-settings-default-value", function () { input_value = $(this).val(); + field_name = $(this).data("advance-field"); update_input(input_value); } ); @@ -4480,6 +4509,17 @@ ".ur-general-setting.ur-general-setting-hidden-value input", function () { input_value = $(this).val(); + field_name = $(this).data("field"); + update_input(input_value); + } + ); + + $(document.body).on( + "change", + ".ur_advance_setting.ur-settings-pattern_value", + function () { + input_value = $(this).val(); + field_name = $(this).data("advance-field"); update_input(input_value); } ); @@ -4487,7 +4527,7 @@ /** * For update the default value. */ - function update_input(input_value) { + function update_input(field_name,input_value) { active_field = $(".ur-item-active"); target_input_field = $(active_field).find( ".user-registration-field-option-group.ur-advance-setting-block" @@ -4496,10 +4536,10 @@ ".ur-advance-setting.ur-advance-default_value" ); target_input = $(ur_toggle_content).find( - "input[data-id=text_advance_setting_default_value]" + 'input[data-advance-field="' + field_name + '"]' ); target_textarea = $(ur_toggle_content).find( - "input[data-id=textarea_advance_setting_default_value]" + 'input[data-advance-field="' + field_name + '"]' ); target_input_hidden_field = $(active_field).find( @@ -4509,12 +4549,19 @@ ".ur-general-setting.ur-general-setting-hidden-value" ); target_hidden_input = $(ur_toggle_hidden_content).find( - 'input[data-field="hidden_value"]' + 'input[data-field="' + field_name + '"]' + ); + // pattern value + ur_toggle_pattern_content = target_input_field.find( + ".ur-advance-setting.ur-advance-pattern_value" + ); + target_pattern_input = $(ur_toggle_pattern_content).find( + 'input[data-advance-field="' + field_name + '"]' ); - target_input.val(input_value); target_textarea.val(input_value); target_hidden_input.val(input_value); + target_pattern_input.val(input_value); } /** diff --git a/includes/abstracts/abstract-ur-field-settings.php b/includes/abstracts/abstract-ur-field-settings.php index 61d816c9d..1c02da417 100644 --- a/includes/abstracts/abstract-ur-field-settings.php +++ b/includes/abstracts/abstract-ur-field-settings.php @@ -91,6 +91,11 @@ public function render_html( $fields ) { $smart_tags = apply_filters( 'ur_smart_tags_list_in_general', $smart_tags ); } + $pattern_validationList = ''; + if ( 'pattern_value' === $field_key ) { + $pattern_validationList = apply_filters( 'ur_pattern_validation_list_in_advanced_settings', $pattern_validationList ); + } + $this->fields_html .= '
'; if ( 'toggle' !== $field['type'] ) { @@ -121,6 +126,7 @@ public function render_html( $fields ) { $this->fields_html .= ' />'; $this->fields_html .= $smart_tags; + $this->fields_html .= $pattern_validationList; break; case 'select': diff --git a/includes/class-ur-emailer.php b/includes/class-ur-emailer.php index 5650c9ae8..361b0710d 100644 --- a/includes/class-ur-emailer.php +++ b/includes/class-ur-emailer.php @@ -351,8 +351,10 @@ public static function send_mail_to_user( $email, $username, $user_id, $data_htm */ public static function send_mail_to_admin( $user_email, $username, $user_id, $data_html, $name_value, $attachments, $template_id ) { - $header = "Reply-To: {{email}} \r\n"; - $header .= 'Content-Type: text/html; charset=UTF-8'; + $header = array( + 'Reply-To:' . $user_email . '\r\n', + 'Content-Type: text/html; charset=UTF-8' + ); $attachment = isset( $attachments['admin'] ) ? $attachments['admin'] : ''; $admin_email = get_option( 'user_registration_admin_email_receipents', get_option( 'admin_email' ) ); @@ -387,7 +389,6 @@ public static function send_mail_to_admin( $user_email, $username, $user_id, $da list( $message, $subject ) = user_registration_email_content_overrider( ur_get_form_id_by_userid( $user_id ), $settings, $message, $subject ); $message = self::parse_smart_tags( $message, $values, $name_value ); $subject = self::parse_smart_tags( $subject, $values, $name_value ); - $header = self::parse_smart_tags( $header, $values, $name_value ); if ( ur_option_checked( 'user_registration_enable_admin_email', true ) ) { foreach ( $admin_email as $email ) { @@ -523,8 +524,10 @@ public static function lost_password_email( $user_login, $user_data, $key ) { */ public static function send_profile_changed_email_to_admin( $user_email, $username, $user_id, $data_html, $name_value, $attachments ) { - $header = "Reply-To: {{email}} \r\n"; - $header .= 'Content-Type: text/html; charset=UTF-8'; + $header = array( + 'Reply-To:' . $user_email . '\r\n', + 'Content-Type: text/html; charset=UTF-8' + ); $attachment = isset( $attachments['admin'] ) ? $attachments['admin'] : ''; $admin_email = get_option( 'user_registration_edit_profile_email_receipents', get_option( 'admin_email' ) ); @@ -547,7 +550,7 @@ public static function send_profile_changed_email_to_admin( $user_email, $userna list( $message, $subject ) = user_registration_email_content_overrider( $form_id, $settings, $message, $subject ); $message = self::parse_smart_tags( $message, $values, $name_value ); $subject = self::parse_smart_tags( $subject, $values, $name_value ); - $header = self::parse_smart_tags( $header, $values, $name_value ); + if ( ur_option_checked( 'user_registration_enable_profile_details_changed_email', true ) ) { foreach ( $admin_email as $email ) { diff --git a/includes/class-ur-smart-tags.php b/includes/class-ur-smart-tags.php index bd5381cca..7b4aef9b0 100644 --- a/includes/class-ur-smart-tags.php +++ b/includes/class-ur-smart-tags.php @@ -18,6 +18,7 @@ class UR_Smart_Tags { public function __construct() { add_filter( 'user_registration_process_smart_tags', array( $this, 'process' ), 10, 3 ); add_filter( 'ur_smart_tags_list_in_general', array( $this, 'select_smart_tags_in_general' ), 10, 1 ); + add_filter( 'ur_pattern_validation_list_in_advanced_settings', array( $this, 'select_pattern_validation' ), 10, 1 ); } /** @@ -356,6 +357,68 @@ public function select_smart_tags_in_general( $smart_tags ) { $smart_tags .= '
'; return $smart_tags; } + + /** + * List of Pattern which can checked against. + * + * @return array array of pattern lists. + */ + public static function ur_pattern_validation_lists() { + $pattern_lists = apply_filters( + 'user_registration_pattern_validation_lists', + array( + '^[a-zA-Z]+$' => __( 'Alpha', 'user-registration' ), + '^[a-zA-Z0-9]+$' => __( 'Alphanumeric', 'user-registration' ), + '^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$' => __( 'Color', 'user-registration' ), + '^[A-Za-z]{2}$' => __( 'Country Code (2 Character)', 'user-registration' ), + '^[A-Za-z]{3}$' => __( 'Country Code (3 Character)', 'user-registration' ), + '^(0[1-9]|1[0-2])\/(0[1-9]|1\d|2\d|3[01])$' => __( 'Date (mm/dd)', 'user-registration' ), + '^(0[1-9]|1\d|2\d|3[01])\/(0[1-9]|1[0-2])$' => __( 'Date (dd/mm)', 'user-registration' ), + '^(0[1-9]|1[0-2])\.(0[1-9]|1\d|2\d|3[01])\.\d{4}$' => __( 'Date (mm.dd.yyyy)', 'user-registration' ), + '^(0[1-9]|1\d|2\d|3[01])\.(0[1-9]|1[0-2])\.\d{4}$' => __( 'Date (dd.mm.yyyy)', 'user-registration' ), + '^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|1\d|2\d|3[01])$' => __( 'Date (yyyy-mm-dd)', 'user-registration' ), + '^(0[1-9]|1[0-2])\/(0[1-9]|1\d|2\d|3[01])\/\d{4}$' => __( 'Date (mm/dd/yyyy)', 'user-registration' ), + '^(0[1-9]|1\d|2\d|3[01])\/(0[1-9]|1[0-2])\/\d{4}$' => __( 'Date (dd/mm/yyyy)', 'user-registration' ), + '^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$' => __( 'Email', 'user-registration' ), + '^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$' => __( 'IP (Version 4)', 'user-registration' ), + '((^|:)([0-9a-fA-F]{0,4})){1,8}$' => __( 'IP (Version 6)', 'user-registration' ), + '^978(?:-[\d]+){3}-[\d]$' => __( 'ISBN', 'user-registration' ), + '-?\d{1,3}\.\d+' => __( 'Latitude or Longitude', 'user-registration' ), + '^[0-9]+$' => __( 'Numeric', 'user-registration' ), + '^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?!.*\s).*$' => __( 'Password (Numeric, lower, upper)', 'user-registration' ), + '(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}' => __( 'Password (Numeric, lower, upper, min 8)', 'user-registration' ), + '[0-9+()-. ]+' => __( 'Phone - General', 'user-registration' ), + '^\+44\d{10}$' => __( 'Phone - UK', 'user-registration' ), + '\d{3}[\-]\d{3}[\-]\d{4}' => __( 'Phone - US: 123-456-7890', 'user-registration' ), + '\([0-9]{3}\)[0-9]{3}-[0-9]{4}' => __( 'Phone - US: (123)456-7890', 'user-registration' ), + '(?:\(\d{3}\)|\d{3})[- ]?\d{3}[- ]?\d{4}' => __( 'Phone - US: Flexible', 'user-registration' ), + '^[A-Za-z]{1,2}\d{1,2}[A-Za-z]?\s?\d[A-Za-z]{2}$' => __( 'Postal Code (UK)', 'user-registration' ), + '\d+(\.\d{2})?$' => __( 'Price (1.23)', 'user-registration' ), + '^[a-zA-Z0-9-]+$' => __( 'Slug', 'user-registration' ), + '(0[0-9]|1[0-9]|2[0-3])(:[0-5][0-9]){2}' => __( 'Time (hh:mm:ss)', 'user-registration' ), + '^(https?|ftp):\/\/[^\s\/$.?#].[^\s]*$' => __( 'URL', 'user-registration' ), + '(\d{5}([\-]\d{4})?)' => __( 'Zip Code', 'user-registration' ), + ) + ); + return $pattern_lists; + } + + /** + * Smart tag list button in general setting and advanced settin of field. + * + * @param string $smart_tags list of smart tags. + */ + public function select_pattern_validation( $pattern_lists ) { + $pattern_validation_list = self::ur_pattern_validation_lists(); + $pattern_lists .= ''; + $pattern_lists .= ''; + return $pattern_lists; + } } new UR_Smart_Tags();