ipl\Html\Form: tweak error handling

This commit is contained in:
Thomas Gelf 2018-06-11 21:47:28 +02:00
parent 5e0b237d2d
commit c587067a33
1 changed files with 9 additions and 8 deletions

View File

@ -70,7 +70,12 @@ class Form extends BaseHtmlElement
$this->ensureAssembled(); $this->ensureAssembled();
if ($this->hasBeenSubmitted()) { if ($this->hasBeenSubmitted()) {
if ($this->isValid()) { if ($this->isValid()) {
try {
$this->onSuccess(); $this->onSuccess();
} catch (\Exception $e) {
$this->addMessage($e->getMessage());
$this->onError();
}
} else { } else {
$this->onError(); $this->onError();
} }
@ -88,16 +93,12 @@ class Form extends BaseHtmlElement
public function onError() public function onError()
{ {
/**
$error = Html::tag('p', ['class' => 'error'], 'ERROR: '); $error = Html::tag('p', ['class' => 'error'], 'ERROR: ');
foreach ($this->getElements() as $element) { foreach ($this->getMessages() as $message) {
foreach ($element->getMessages() as $message) { $error->add($message);
$error->add(sprintf('%s: %s', $element->getName(), $message));
}
} }
$this->add($error); $this->prepend($error);
*/
} }
// TODO: onElementRegistered // TODO: onElementRegistered