Validation Rules Example

Somebody please give me an example of how to write good validation rules and scenarios

Let’s consider this table:


id - primary key, set by db

parent_id - foreign key, set by form

owner_id - foreign key, set by script, w/o form

field_1, field_2, ..., field_n - some data, required, set by form

another_field_1, another_field_2, ..., another_field_n - some data, can be empty/null, set by form

is_disabled - active flag, set by form during administration process




and these scenarios: update by user, update by admin, delete.

In this table example some fields (field_1 … field_n, another_field_1 … another_field_n) require strong validation (required, trim, strip_tags), some probably should also be validated (parent_id, owner_id - integer), and some must be assigned only in several scenarios (is_disabled - only for admin)

And we cannot use ‘default’ scenario here.

So when I’ve tried to write all these rules, my code became bulky. Any chance to do it in a couple of lines?..

Btw here’s the answer I was looking for.