public static function getSubscribedEvents()
{
return [
'onPluginsInitialized' => ['onPluginsInitialized', 0],
'onFormProcessed' => ['onFormProcessed', 0]
];
}
public function onFormProcessed(Event $event)
{
$action = $event['action'];
switch ($action) {
case 'answer':
$this->grav->fireEvent('onFormValidationError', new Event([
'form' => $form,
'message' => $this->grav['language']->translate('This is an error')
]));
$event->stopPropagation();
return;
break;
}
}
I just wanted to submit this form and retrieve a custom error, just to see if the function works properly.
But every time, I get the same error: Oops there was a problem, please check your input and submit the form again.
This is a bit more complicated than on the frontend. You can use the onAdminSave event to handle special saving from the admin, but I don’t have a good example right now. I hope to release some more information including a sample plugin soon.
With this I’m sure that my function works properly, at least. In fact, after submitting the form the function adds a new row on the specified file, but only on onFormValidationError and not on onFormProcessed or onAdminSave.