Michael Lenaghan Posted April 9 Share Posted April 9 I created a `Fieldset (Page)` field with two fields, a start year and an end year. Is there some way to add validation that guarantees start year <= end year? (If, that is, they're specified at all; both fields should be optional.) Link to comment Share on other sites More sharing options...
wbmnfktr Posted April 10 Share Posted April 10 The easiest way would probably be to use hooks in ready.php - something like the pseudo-code below: $pages->addHookBefore('Pages::saveReady', function(HookEvent $event) { $page = $event->arguments(0); // todo: change template name if($page->template == "your-template" { // todo: change field names $field1 = $page->dateStart; $field2 = $page->dateEnd; // todo: add validation if($field1 > $field2) { // show a message // whatever } } }); This would hook into the save process just before the page would be saved. Therefore you could check if the fields validate. Link to comment Share on other sites More sharing options...
Michael Lenaghan Posted April 10 Author Share Posted April 10 OK, thanks for that! 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