Grizzzzzzzzzz wrote:why can't you use functions?
I don't understand why I would need functions for this. I don't want to put code in a variable to save code duplication or anything.
I didn't really want to blast you all with a wall of text about what this is for but I guess I'll have to..
I'm storing a set of validation rules for each field in a form, in a database. When a field needs to be validated, PHP will check the database for any validation rules (which will be in the form of PHP code) and execute them. I don't want to set a static list of possible validation rules because I'm making a highly configurable CMS.
The database would store something like this:
Code: Select all
[Field] "ID"
[Rule] "is_numeric({datum}) === false"
[Response] "Animal ID must be a number"
[Field] "Animal"
[Rule] "{datum} === 'cat'"
[Response] "A cat is not an animal"
[Field] "Animal"
[Rule] "{datum} === ''"
[Response] "Please enter something"
Then PHP would replace {datum} with the variable in subject (eg, $_POST['animal']), execute the code, and if the operation returns true then send an error message.
So it would generate and execute this code:
Code: Select all
if((is_numeric($_POST['id']) === false) === true) {
die("Animal ID must be a number");
}
if(($_POST['animal'] === 'cat') === true) {
die("A cat is not an animal");
}
if(($_POST['animal'] === '') === true) {
die("Please enter something");
}