Skip to content
● Grav 2.2 is out: 2x faster cold starts and 96% less memory on big sites. Read the announcement →

Returning error message from form validation

Started by Muut Archive 10 years ago · 2 replies · 553 views
10 years ago

Is there a mechanism for returning a error message after (custom) validation of a form?

PHP
$event->stopPropagation();
return;

just returns the user to the form.

10 years ago

Have a look at the Form plugin's onFormProcessed method in the form.php file, where you'll find some lines of code similar to:

PHP
$this->grav->fireEvent('onFormValidationError', 
new Event([
     'form'    => $form,
     'message' => 'some message'
]));
$event->stopPropagation();

return;

That should work for you.

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 2597 9 years ago
Archive · by Muut Archive, 9 years ago
2 1706 9 years ago
Archive · by Muut Archive, 9 years ago
2 4999 9 years ago
Archive · by Muut Archive, 9 years ago
1 3830 9 years ago
Archive · by Muut Archive, 9 years ago
3 1814 9 years ago