- Timestamp:
- 10/14/2026 04:54:36 PM (2 weeks ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
formidable/trunk/classes/models/fields/FrmFieldUrl.php
r3688662 r3746820 26 26 protected function field_settings_for_type() { 27 27 return array( 28 'size' => true, 29 'clear_on_focus' => true, 30 'invalid' => true, 31 'show_image' => true, 28 'size' => true, 29 'clear_on_focus' => true, 30 'invalid' => true, 31 'show_image' => true, 32 'allow_intl_domains' => true, 32 33 ); 33 34 } … … 38 39 protected function extra_field_opts() { 39 40 return array( 40 'show_image' => 0, 41 'show_image' => 0, 42 'allow_intl_domains' => 0, 41 43 ); 42 44 } … … 83 85 $errors = array(); 84 86 85 // Validate the url format 86 if ( $value && ! preg_match( '/^http(s)?:\/\/(?:localhost|(?:[\da-z\.-]+\.[\da-z\.-]+))/i', $value ) ) {87 // Validate the url format. 88 if ( $value && ! preg_match( $this->get_url_pattern(), $value ) ) { 87 89 $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $this->field, 'invalid' ); 88 // skipcq: PHP-W1067 -- $this->field is always a field object by the time validate() runs; FrmFieldType's constructor just accepts array|int|object for lazy construction elsewhere.90 // skipcq: PHP-W1067 -- $this->field is always a field object by the time validate() runs; FrmFieldType's constructor just accepts array|int|object for lazy construction elsewhere. 89 91 } elseif ( $this->field->required == '1' && ! $value ) { // phpcs:ignore Universal.Operators.StrictComparisons 90 92 $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $this->field, 'blank' ); … … 92 94 93 95 return $errors; 96 } 97 98 /** 99 * Gets the regular expression used to validate the url format. 100 * 101 * @since 7.0 102 * 103 * @return string 104 */ 105 private function get_url_pattern() { 106 if ( ! $this->allows_intl_domains() ) { 107 return '/^http(s)?:\/\/(?:localhost|(?:[\da-z\.-]+\.[\da-z\.-]+))/i'; 108 } 109 110 // The host class allows \x80-\xff so internationalized domain names pass. 111 // Byte range by design, and no /u modifier: with /u, preg_match() returns false on invalid UTF-8. 112 return '/^http(s)?:\/\/(?:localhost|(?:[\da-z\x80-\xff\.-]+\.[\da-z\x80-\xff\.-]+))/i'; 113 } 114 115 /** 116 * Checks if the field accepts internationalized domain names. 117 * 118 * @since 7.0 119 * 120 * @return bool 121 */ 122 private function allows_intl_domains() { 123 return (bool) FrmField::get_option( $this->field, 'allow_intl_domains' ); 124 } 125 126 /** 127 * Flags the input so the javascript validation accepts internationalized domain names too. 128 * 129 * @since 7.0 130 * 131 * @param array $args Field arguments. 132 * @param string $input_html The HTML attributes for the input. 133 * 134 * @return void 135 */ 136 protected function add_extra_html_atts( $args, &$input_html ) { 137 if ( $this->allows_intl_domains() ) { 138 $input_html .= ' data-intl-domains="1"'; 139 } 94 140 } 95 141
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)