Skip to content

Commit

Permalink
Form: fix onError, catch Errors in onSuccess
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas-Gelf committed Mar 26, 2019
1 parent b8851d7 commit afa0ffc
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/Form.php
Expand Up @@ -55,7 +55,12 @@ public function handleRequest(ServerRequestInterface $request)
$this->ensureAssembled();
if ($this->hasBeenSubmitted()) {
if ($this->isValid()) {
$this->onSuccess();
try {
$this->onSuccess();
} catch (Exception $e) {
$this->addMessage($e);
$this->onError();
}
} else {
$this->onError();
}
Expand All @@ -82,16 +87,15 @@ public function onSuccess()

public function onError()
{
/**
$error = Html::tag('p', ['class' => 'error'], 'ERROR: ');
foreach ($this->getElements() as $element) {
foreach ($element->getMessages() as $message) {
$error->add(sprintf('%s: %s', $element->getName(), $message));
$error = Html::tag('p', ['class' => 'error']);
foreach ($this->getMessages() as $message) {
if ($message instanceof Exception) {
$error->add($message->getMessage());
} else {
$error->add($message);
}
}
$this->add($error);
*/
$this->prepend($error);
}

public function isValid()
Expand Down

0 comments on commit afa0ffc

Please sign in to comment.