I have a plugin that has a few settings. One of which is a start date and and end date. Everything is set up and working fine. I'd like to validate the start/end dates a a bit though.
I am able to use compare
to check that the end isn't before the start, but I'd also like to check that the start (or end) isn't in the past as well.
Using this awesome page on validation I've seen how to set custom validation via rules
. But, since I'm in a settings file, I'm not exactly sure how this translates over.
MyPlugin.php
defineSettings(){
return array(
'myStartDate' => array(
AttributeType::DateTime,
'required': true,
'compare': '<= myEndDate'
),
'myEndDate' => array(
AttributeType::DateTime,
'required': true,
'compare': '>= myStartDate'
),
)
}
What I think I'm trying to get is something like this:
....
'myStartDate' => array(
AttributeType::DateTime,
'required': true,
'something': array(
'rule': myValidation,
'message': 'The start date can not be after the finish date.'
)
)
....
function myValidation() {
// Do something here
}
Or, maybe I'm way off.