private function setFieldErrorsAndFocus(array $nodes)
    {
        foreach ($nodes as $nodeKey => $node) {
            if (!($node instanceof Field) && !($node instanceof Fieldset)) {
                throw new \Exception('Invalid node');
            }

            if ($node instanceof Field) {
                if (method_exists($node, 'getValue') && mb_strlen($node->getValue()) == 0 && mb_strlen($this->focusFieldId) == 0) {
                    $this->focusFieldId = $node->getId();
                }

                if ($node->getError()) {
                    $this->fieldErrorMessages[] = $node->getErrorMessage();
                    if (!$this->hasError()) {
                        $this->errorMessage = self::GENERAL_ERROR_MESSAGE;
                        $this->focusFieldId = $node->getId();
                    }
                }

            } else {
                // Fieldset
                if (!$this->hasError()) {
                    if ($node->hasError()) {
                        $this->errorMessage = self::GENERAL_ERROR_MESSAGE;
                    }
                    $this->setFieldErrorsAndFocus($node->getNodes());
                }
            }
        }
    }
private function setFieldErrorsAndFocus(array $nodes)
    {
        foreach ($nodes as $nodeKey => $node) {
            if (!($node instanceof Field) && !($node instanceof Fieldset)) {
                throw new \Exception('Invalid node');
            }

            if ($node instanceof Field) {
                if (method_exists($node, 'getValue') && mb_strlen($node->getValue()) == 0 && mb_strlen($this->focusFieldId) == 0) {
                    $this->focusFieldId = $node->getId();
                }

                if ($node->getError()) {
                    $this->fieldErrorMessages[] = $node->getErrorMessage();
                    if (!$this->hasError()) {
                        $this->errorMessage = self::GENERAL_ERROR_MESSAGE;
                        $this->focusFieldId = $node->getId();
                    }
                }

            } else {
                // Fieldset
                if (!$this->hasError()) {
                    if ($node->hasError()) {
                        $this->errorMessage = self::GENERAL_ERROR_MESSAGE;
                    }
                    $this->setFieldErrorsAndFocus($node->getNodes());
                }
            }
        }
    }
private function setFieldErrorsAndFocus ( array $ nodes ) { foreach ( $ nodes as $ nodeKey => $ node ) { if ( ! ( $ node instanceof Field ) && ! ( $ node instanceof Fieldset ) ) { throw new \ Exception ( 'Invalid node' ) ; } if ( $ node instanceof Field ) { if ( method_exists ( $ node , 'getValue' ) && mb_strlen ( $ node -> getValue ( ) ) == 0 && mb_strlen ( $ this -> focusFieldId ) == 0 ) { $ this -> focusFieldId = $ node -> getId ( ) ; } if ( $ node -> getError ( ) ) { $ this -> fieldErrorMessages [ ] = $ node -> getErrorMessage ( ) ; if ( ! $ this -> hasError ( ) ) { $ this -> errorMessage = self :: GENERAL_ERROR_MESSAGE ; $ this -> focusFieldId = $ node -> getId ( ) ; } } } else { // Fieldset if ( ! $ this -> hasError ( ) ) { if ( $ node -> hasError ( ) ) { $ this -> errorMessage = self :: GENERAL_ERROR_MESSAGE ; } $ this -> setFieldErrorsAndFocus ( $ node -> getNodes ( ) ) ; } } } }
recursive when encounters a fieldset
recursive when encounters a fieldset