diff --git a/src/Forms/Form.php b/src/Forms/Form.php index a0483b68cc6..63e56e39c9f 100644 --- a/src/Forms/Form.php +++ b/src/Forms/Form.php @@ -1262,17 +1262,26 @@ public function getLegend() */ public function validationResult() { + $result = ValidationResult::create(); + // Automatically pass if there is no validator, or the clicked button is exempt // Note: Soft support here for validation with absent request handler $handler = $this->getRequestHandler(); $action = $handler ? $handler->buttonClicked() : null; - $validator = $this->getValidator(); - if (!$validator || $this->actionIsValidationExempt($action)) { - return ValidationResult::create(); + if ($this->actionIsValidationExempt($action)) { + return $result; + } + + // Invoke FormField validation + foreach ($this->Fields() as $field) { + $result->combineAnd($field->validate()); } // Invoke validator - $result = $validator->validate(); + $validator = $this->getValidator(); + if ($validator) { + $result->combineAnd($validator->validate()); + } $this->loadMessagesFrom($result); return $result; } diff --git a/src/Forms/RequiredFields.php b/src/Forms/RequiredFields.php index 6e2068aba82..624e7cdc7cf 100644 --- a/src/Forms/RequiredFields.php +++ b/src/Forms/RequiredFields.php @@ -86,12 +86,6 @@ public function php($data) $valid = true; $fields = $this->form->Fields(); - foreach ($fields as $field) { - $result = $field->validate(); - $valid = $result->isValid() && $valid; - $this->result->combineAnd($result); - } - if (!$this->required) { return $valid; }