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();
|
$this->ensureAssembled();
|
||||||
if ($this->hasBeenSubmitted()) {
|
if ($this->hasBeenSubmitted()) {
|
||||||
if ($this->isValid()) {
|
if ($this->isValid()) {
|
||||||
$this->onSuccess();
|
try {
|
||||||
|
$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
|
||||||
|
|
Loading…
Reference in New Issue