Jump to content

Recommended Posts

Posted

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.)

Posted

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.

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...