public function checkFields(array &$errors, $checkForDuplicates = true)
    {
        $parent_section = $this->get('parent_section');
        $label = $this->get('label');
        $element_name = $this->get('element_name');

        if (Lang::isUnicodeCompiled()) {
            $valid_name = preg_match('/^[\p{L}]([0-9\p{L}\.\-\_]+)?$/u', $element_name);
        } else {
            $valid_name = preg_match('/^[A-z]([\w\d\-_\.]+)?$/i', $element_name);
        }

        if ($label === '') {
            $errors['label'] = __('This is a required field.');
        } elseif (strtolower($label) === 'id') {
            $errors['label'] = __('%s is a reserved name used by the system and is not allowed for a field handle. Try using %s instead.', array('<code>ID</code>', '<code>UID</code>'));
        }

        if ($element_name === '') {
            $errors['element_name'] = __('This is a required field.');
        } elseif ($element_name === 'id') {
            $errors['element_name'] = __('%s is a reserved name used by the system and is not allowed for a field handle. Try using %s instead.', array('<code>id</code>', '<code>uid</code>'));
        } elseif (!$valid_name) {
            $errors['element_name'] = __('Invalid element name. Must be valid %s.', array('<code>QName</code>'));
        } elseif ($checkForDuplicates) {
            if (FieldManager::fetchFieldIDFromElementName($element_name, $parent_section) !== $this->get('id')) {
                $errors['element_name'] = __('A field with that element name already exists. Please choose another.');
            }
        }

        // Check that if the validator is provided that it's a valid regular expression
        if (!is_null($this->get('validator')) && $this->get('validator') !== '') {
            if (@preg_match($this->get('validator'), 'teststring') === false) {
                $errors['validator'] = __('Validation rule is not a valid regular expression');
            }
        }

        return (!empty($errors) ? self::__ERROR__ : self::__OK__);
    }
public function checkFields(array &$errors, $checkForDuplicates = true)
    {
        $parent_section = $this->get('parent_section');
        $label = $this->get('label');
        $element_name = $this->get('element_name');

        if (Lang::isUnicodeCompiled()) {
            $valid_name = preg_match('/^[\p{L}]([0-9\p{L}\.\-\_]+)?$/u', $element_name);
        } else {
            $valid_name = preg_match('/^[A-z]([\w\d\-_\.]+)?$/i', $element_name);
        }

        if ($label === '') {
            $errors['label'] = __('This is a required field.');
        } elseif (strtolower($label) === 'id') {
            $errors['label'] = __('%s is a reserved name used by the system and is not allowed for a field handle. Try using %s instead.', array('<code>ID</code>', '<code>UID</code>'));
        }

        if ($element_name === '') {
            $errors['element_name'] = __('This is a required field.');
        } elseif ($element_name === 'id') {
            $errors['element_name'] = __('%s is a reserved name used by the system and is not allowed for a field handle. Try using %s instead.', array('<code>id</code>', '<code>uid</code>'));
        } elseif (!$valid_name) {
            $errors['element_name'] = __('Invalid element name. Must be valid %s.', array('<code>QName</code>'));
        } elseif ($checkForDuplicates) {
            if (FieldManager::fetchFieldIDFromElementName($element_name, $parent_section) !== $this->get('id')) {
                $errors['element_name'] = __('A field with that element name already exists. Please choose another.');
            }
        }

        // Check that if the validator is provided that it's a valid regular expression
        if (!is_null($this->get('validator')) && $this->get('validator') !== '') {
            if (@preg_match($this->get('validator'), 'teststring') === false) {
                $errors['validator'] = __('Validation rule is not a valid regular expression');
            }
        }

        return (!empty($errors) ? self::__ERROR__ : self::__OK__);
    }
public function checkFields ( array & $ errors , $ checkForDuplicates = true ) { $ parent_section = $ this -> get ( 'parent_section' ) ; $ label = $ this -> get ( 'label' ) ; $ element_name = $ this -> get ( 'element_name' ) ; if ( Lang :: isUnicodeCompiled ( ) ) { $ valid_name = preg_match ( '/^[\p{L}]([0-9\p{L}\.\-\_]+)?$/u' , $ element_name ) ; } else { $ valid_name = preg_match ( '/^[A-z]([\w\d\-_\.]+)?$/i' , $ element_name ) ; } if ( $ label === '' ) { $ errors [ 'label' ] = __ ( 'This is a required field.' ) ; } elseif ( strtolower ( $ label ) === 'id' ) { $ errors [ 'label' ] = __ ( '%s is a reserved name used by the system and is not allowed for a field handle. Try using %s instead.' , array ( '<code>ID</code>' , '<code>UID</code>' ) ) ; } if ( $ element_name === '' ) { $ errors [ 'element_name' ] = __ ( 'This is a required field.' ) ; } elseif ( $ element_name === 'id' ) { $ errors [ 'element_name' ] = __ ( '%s is a reserved name used by the system and is not allowed for a field handle. Try using %s instead.' , array ( '<code>id</code>' , '<code>uid</code>' ) ) ; } elseif ( ! $ valid_name ) { $ errors [ 'element_name' ] = __ ( 'Invalid element name. Must be valid %s.' , array ( '<code>QName</code>' ) ) ; } elseif ( $ checkForDuplicates ) { if ( FieldManager :: fetchFieldIDFromElementName ( $ element_name , $ parent_section ) !== $ this -> get ( 'id' ) ) { $ errors [ 'element_name' ] = __ ( 'A field with that element name already exists. Please choose another.' ) ; } } // Check that if the validator is provided that it's a valid regular expression if ( ! is_null ( $ this -> get ( 'validator' ) ) && $ this -> get ( 'validator' ) !== '' ) { if ( @ preg_match ( $ this -> get ( 'validator' ) , 'teststring' ) === false ) { $ errors [ 'validator' ] = __ ( 'Validation rule is not a valid regular expression' ) ; } } return ( ! empty ( $ errors ) ? self :: __ERROR__ : self :: __OK__ ) ; }
Check the field's settings to ensure they are valid on the section
editor

@param array $errors
the array to populate with the errors found.
@param boolean $checkForDuplicates (optional)
if set to true, duplicate Field name's in the same section will be flagged
as errors. Defaults to true.
@return integer
returns the status of the checking. if errors has been populated with
any errors `self::__ERROR__`, `self::__OK__` otherwise.
Check the field s settings to ensure they are valid on the section editor