This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
Seth
The documentation references handling errors after redirect: https://octobercms.com/docs/services/validation#working-with-error-messages
But I'm using ajax in a component, any better way to do this?
Right now I'm doing this in the component:
if ($validator->fails()) {
$result = "Oops, errors found: <br>";
// var_dump($validator->messages());
foreach ($messages->all(':message<br>') as $message)
{
$result .= $message;
}
$this->page['result'] = $result;
$this->page['success'] = false;
return;
}
With this this in the view:
{% if result %}
<div id="result">{{ result }}</div>
{% endif %}
Any better method or example someone can point me to? Thanks! Seth
jfo
A simpler way is to call your model validate()
method from your AJAX method handler.
E.g.:
public function onSomething($recordId = null)
{
$model = $this->formFindModelObject($recordId);
$model->validate(); // this will do the heavy lifting for you
}
1-2 of 2