Open Journal Systems  3.3.0
FormValidatorArray.inc.php
1 <?php
2 
16 import('lib.pkp.classes.form.validation.FormValidator');
17 
19 
21  var $_fields;
22 
25 
34  function __construct(&$form, $field, $type, $message, $fields = array()) {
35  parent::__construct($form, $field, $type, $message);
36  $this->_fields = $fields;
37  $this->_errorFields = array();
38  }
39 
40 
41  //
42  // Setters and Getters
43  //
48  function getErrorFields() {
49  return $this->_errorFields;
50  }
51 
52 
53  //
54  // Public methods
55  //
61  function isValid() {
62  if ($this->getType() == FORM_VALIDATOR_OPTIONAL_VALUE) return true;
63 
64  $data = $this->getFieldValue();
65  if (!is_array($data)) return false;
66 
67  $isValid = true;
68  foreach ($data as $key => $value) {
69  if (count($this->_fields) == 0) {
70  // We expect all fields to contain values.
71  if (is_null($value) || trim((string)$value) == '') {
72  $isValid = false;
73  array_push($this->_errorFields, $this->getField()."[{$key}]");
74  }
75  } else {
76  // In the two-dimensional case we always expect a value array.
77  if (!is_array($value)) {
78  $isValid = false;
79  array_push($this->_errorFields, $this->getField()."[{$key}]");
80  continue;
81  }
82 
83  // Go through all sub-sub-fields and check them explicitly
84  foreach ($this->_fields as $field) {
85  if (!isset($value[$field]) || trim((string)$value[$field]) == '') {
86  $isValid = false;
87  array_push($this->_errorFields, $this->getField()."[{$key}][{$field}]");
88  }
89  }
90  }
91  }
92 
93  return $isValid;
94  }
95 }
96 
97 
FormValidatorArray
Form validation check that checks an array of fields.
Definition: FormValidatorArray.inc.php:18
FormValidator\getField
getField()
Definition: FormValidator.inc.php:84
FormValidatorArray\$_fields
$_fields
Definition: FormValidatorArray.inc.php:24
FormValidatorArray\__construct
__construct(&$form, $field, $type, $message, $fields=array())
Definition: FormValidatorArray.inc.php:40
FormValidatorArray\isValid
isValid()
Definition: FormValidatorArray.inc.php:67
FormValidatorArray\$_errorFields
$_errorFields
Definition: FormValidatorArray.inc.php:30
FormValidator\getType
getType()
Definition: FormValidator.inc.php:116
FormValidator
Class to represent a form validation check.
Definition: FormValidator.inc.php:23
FormValidatorArray\getErrorFields
getErrorFields()
Definition: FormValidatorArray.inc.php:54
FormValidator\getFieldValue
getFieldValue()
Definition: FormValidator.inc.php:154