Plugin Directory


Ignore:
Timestamp:
10/14/2026 04:54:36 PM (2 weeks ago)
Author:
formidableforms
Message:

Update to version 7.0 from GitHub

File:
1 edited

Legend:

Unmodified
Added
Removed
  • formidable/trunk/classes/models/fields/FrmFieldUrl.php

    r3688662 r3746820  
    2626        protected function field_settings_for_type() {
    2727                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,
    3233                );
    3334        }
    … …  
    3839        protected function extra_field_opts() {
    3940                return array(
    40                         'show_image' => 0,
     41                        'show_image'         => 0,
     42                        'allow_intl_domains' => 0,
    4143                );
    4244        }
    … …  
    8385                $errors = array();
    8486
    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 ) ) {
    8789                        $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.
    8991                } elseif ( $this->field->required == '1' && ! $value ) { // phpcs:ignore Universal.Operators.StrictComparisons
    9092                        $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $this->field, 'blank' );
    … …  
    9294
    9395                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                }
    94140        }
    95141
Note: See TracChangeset for help on using the changeset viewer.