For my framework I've written down this concept to solve the form validation problem. I want it to be as straightforward as possible for the framework user.Every Form (=object) has one or many FormElements (=objects). Every FormElement can have 0-n FormValidators (=objects). Everything easily configured through the backend (simple drag&drop stuff).When the Form View is rendered, it loops over all the FormElements, and for each of them it loops over all their associated FormValidators. That way it builds up all the needed JavaScript to validate the form on client side.A FormValidator is an lightweight object which defines only these seven things:
- PHP class name of the validation utility class
- method name of the validation utility class, which must be called
- a string for additional arguments (comma-separated values)
- JavaScript "class" name of the validation utility
- "method" name which must be called
- a tring for additional arguments (comma-separated values)
- an associated ErrorInfo object which contains an formatted error message