diff --git a/src/fieldwork/Form.php b/src/fieldwork/Form.php
index c3e8eb2..209dfcc 100644
--- a/src/fieldwork/Form.php
+++ b/src/fieldwork/Form.php
@@ -251,11 +251,23 @@ public function getScriptHTML ()
return $openingTag . $this->getScript() . $closingTag;
}
- public function renderFormError ($errorMsg)
+ static public function renderFormError ($errorMsg)
{
return sprintf("
", $errorMsg);
}
+ /**
+ * Get all the error messages for form-wide validators that returned invalid
+ */
+ public function getFormErrors ()
+ {
+ return array_map(function (FormValidator $formValidator) {
+ return $formValidator->getErrorMsg();
+ }, array_filter($this->validators, function (FormValidator $validator) {
+ return !$validator->isValid();
+ }));
+ }
+
/**
* Gets the markup that is to be outputted before the actual contents of the form. This method could be used for
* even more manual control over outputting with a custom markup.
@@ -264,11 +276,9 @@ public function renderFormError ($errorMsg)
public function getWrapBefore ()
{
$dataFields = $this->getDataFieldsHTML();
- $errors = '';
- foreach ($this->validators as $validator)
- /* @var $validator FormValidator */
- if (!$validator->isValid())
- $errors .= $this->renderFormError($validator->getErrorMsg());
+ $errors = join(array_map(function ($errorMsg) {
+ return Form::renderFormError($errorMsg);
+ }, $this->getFormErrors()));
return "