_fields = $fields; $this->_errorFields = []; } // // Setters and Getters // /** * Get array of fields where an error occurred. * * @return array */ public function getErrorFields() { return $this->_errorFields; } // // Public methods // /** * @see FormValidator::isValid() * Value is valid if it is empty and optional or all field values are set. * * @return bool */ public function isValid() { if ($this->getType() == FormValidator::FORM_VALIDATOR_OPTIONAL_VALUE) { return true; } $data = $this->getFieldValue(); if (!is_array($data)) { return false; } $isValid = true; foreach ($data as $key => $value) { if (count($this->_fields) == 0) { // We expect all fields to contain values. if (is_null($value) || trim((string)$value) == '') { $isValid = false; array_push($this->_errorFields, $this->getField() . "[{$key}]"); } } else { // In the two-dimensional case we always expect a value array. if (!is_array($value)) { $isValid = false; array_push($this->_errorFields, $this->getField() . "[{$key}]"); continue; } // Go through all sub-sub-fields and check them explicitly foreach ($this->_fields as $field) { if (!isset($value[$field]) || trim((string)$value[$field]) == '') { $isValid = false; array_push($this->_errorFields, $this->getField() . "[{$key}][{$field}]"); } } } } return $isValid; } } if (!PKP_STRICT_MODE) { class_alias('\PKP\form\validation\FormValidatorArray', '\FormValidatorArray'); }