The onBeforeValidate handler is used for when an editor saves a piece of content, but before LiveWhale validates the data, you can perform your own custom validation.
(Note, the $id variable will only be populated when saving an existing piece of content. When creating new content, it will be blank.)
To add a validation check, look to the $_LW->POST
array for the submitted values, and add error messages to the $_LW->REGISTERED_MESSAGES['failure']
array as needed.
<?php
$_LW->REGISTERED_APPS['my_app']=[
'title'=>'My App',
'handlers'=>['onBeforeValidate'],
];
class LiveWhaleApplicationMyApp {
public function onBeforeValidate($data_type, $id) {
global $_LW;
// if saving an event from a backend editor
if ($data_type=='events' && ($_LW->page=='events_edit' || $_LW->page=='events_sub_edit')) {
if (empty($_LW->_POST['images'])) { // require an image
$_LW->REGISTERED_MESSAGES['failure'][]='You must attach an image to your event.';
};
};
}
}
?>