« All Handlers

onBeforeValidate

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?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.';
};
};

}

}
?>