Juergen Posted January 27, 2017 Share Posted January 27, 2017 Here is a tipp for you if you want to check for validation errors in inputfields before processing php code inside a Hook function. My goal was to run the code inside the Hook function only if there are no errors after processing the form in the backend. $pages->addHookBefore('saveReady', function($event) { $page = $event->arguments[0]; //count errors during input process $errors = $page->errors('all'); $errors = count($errors); if ($errors == 0) { ......//run your code } }); In this case I run a Hook before "saveReady" inside my ready.php. But I only want to run my php.code inside this Hook function if there are no errors in the form submission. So I need to check for errors in the form submission first. These 3 simple lines of code are necessary: $page = $event->arguments[0]; //count errors during input process $errors = $page->errors('all'); $errors = count($errors); The first step is to define the page variable $page; Second step is to get the error array Last step is to count the entries in the array to get the number of the errors Thats all! Afterwards you can use the number of errors in an if-statement to run the code only if there are no errors. Hope this will be helpful for someone. 6 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now