ipl\Html\Form: tweak error handling
This commit is contained in:
parent
5e0b237d2d
commit
c587067a33
|
@ -70,7 +70,12 @@ class Form extends BaseHtmlElement
|
|||
$this->ensureAssembled();
|
||||
if ($this->hasBeenSubmitted()) {
|
||||
if ($this->isValid()) {
|
||||
$this->onSuccess();
|
||||
try {
|
||||
$this->onSuccess();
|
||||
} catch (\Exception $e) {
|
||||
$this->addMessage($e->getMessage());
|
||||
$this->onError();
|
||||
}
|
||||
} else {
|
||||
$this->onError();
|
||||
}
|
||||
|
@ -88,16 +93,12 @@ class Form extends BaseHtmlElement
|
|||
|
||||
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));
|
||||
}
|
||||
foreach ($this->getMessages() as $message) {
|
||||
$error->add($message);
|
||||
}
|
||||
|
||||
$this->add($error);
|
||||
*/
|
||||
$this->prepend($error);
|
||||
}
|
||||
|
||||
// TODO: onElementRegistered
|
||||
|
|
Loading…
Reference in New Issue