Field Types sanitation

#1

Hi guys,

First of all, I like Cockpit very much.

Now with the question, I realized that the only Field Types that are being sanitized are text, boolean, number, url, email and password (modules/Collections/bootstrap.php), so, is the idea behind all of this to leave it like that and keep it simple and leave the developer to be responsible of the other Field Types or is just work that needs to be done?

Thank you!

0 Likes

#2

you can inject your custom validation via an event hook:

(snippet should be located in config/bootstrap.php)


$app->on('collections.save.before.MyCollection', function($name, &$entry, $isUpdate) {

    $check = true;
    
    // do custom validation e.g. if ($entry['name'] !== 'John') $check = false

    if (!$check) {
       $this->stop(['error' => "Validation error"], 412);
    }
    
});

Replace MyCollection with your collection name

0 Likes