I've been looking at http://straightupcraft.com/articles/the-definitive-guide-to-validation-in-craft which seems to concentrate on custom models. However I am looking to validate data posted to a plugin that stores that data as core EntryModels.
So let's say you create a Section and assign some Fields in its field layout. You can set each Field to be required but I want to do more than that and check if it's an integer or if it's unique.
I am currently doing that in my service class:
private function validateReference()
{
$reference = craft()->request->getPost('reference');
$existingEntryCount = craft()->elements->getCriteria(ElementType::Entry)->total(array(
'reference' => $reference
));
return ($existingEntryCount === 0);
}
That all works but I am wondering if instead I should be setting the validation properties of each Field in this service and then just running a core validate method?