Jump to content

Pre-Save Validation (AdminPreSaveValidation)


Recommended Posts

Github: https://github.com/thetuningspoon/AdminPreSaveValidation




This module prevents admin editors from saving changes to a page that has one or more invalid fields. It uses an ajax call to check for errors and javascript to populate the page edit form with any error messages that were returned. This way the user can correct the issues and resubmit the form without invalid data getting saved to the database or the editor losing changes.

I've wanted a way to implement this common workflow in ProcessWire for some time now and this relatively simple ajax-based approach makes it possible without getting too much in the way of how ProcessWire normally works. For example, all of the post-save actions (Save + Exit, Save + View, etc.) still work as usual. The only downside is that a successful save will take a bit longer as it involves two sequential http requests (the initial ajax request that checks for errors and the normal page submit after no errors are returned).

This module has also been tested successfully with repeaters and other nested inputs.

By hooking after Inputfield::processInput, you can add your own custom validations to inputfields and this module will pick up on and display them as well.

 * Example of hook that adds an error to an inputfield. This will add an error to every input.
$this->wire()->addHookAfter("Inputfield::processInput", function(HookEvent $event) {
   $event->object->error('Invalid input!');

I hope others will find this module useful!

  • Like 13
Link to comment
Share on other sites

  • thetuningspoon changed the title to Pre-Save Validation (AdminPreSaveValidation)

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...