Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

Returning error message from form validation

Started by Muut Archive 10 years ago · 2 replies · 477 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 1366 9 years ago
Archive · by Muut Archive, 9 years ago
2 940 9 years ago
Archive · by Muut Archive, 9 years ago
2 4069 9 years ago
Archive · by Muut Archive, 9 years ago
1 2960 9 years ago
Archive · by Muut Archive, 9 years ago
3 1125 9 years ago