fields = $fields; $this->errorFields = array(); } /** * Check if field value is valid. * Value is valid if it is empty and optional or is in the set of accepted values. * @return boolean */ function isValid() { if ($this->type == 'optional') { return true; } $ret = true; $data = $this->form->getData($this->field); if (!is_array($data)) return false; foreach ($data as $key => $value) { if (count($this->fields) == 0) { if (trim($value) == '') { $ret = false; array_push($this->errorFields, "{$this->field}[{$key}]"); } } else { foreach ($this->fields as $field) { if (trim($value[$field]) == '') { $ret = false; array_push($this->errorFields, "{$this->field}[{$key}][{$field}]"); } } } } return $ret; } /** * Get array of fields where an error occurred. * @return array */ function getErrorFields() { return $this->errorFields; } } ?>