Proposal for a HTML_FormObject class

From: Date: Sun, 25 Jan 2004 13:53:56 +0000
Subject: Proposal for a HTML_FormObject class
Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-25263@lists.php.net to get a copy of this message
Hello! I've made a class for checking, validating and abstracting form data and I think it could help other developers too so I think it would be a good addition to pear. Basicly the user creates a class which represents his form and gives it to the FormObjectValidator class for validation, to define what is needed by his form, he uses a special rule syntax: Example: class Login extends FormObject { var $username = 'post://(string)name//\w*/'; var $password = 'post://(string)pw'; } $Form = FormObjectValidator::Validate(new Login); The Form gets validated with the defined rules and it get returned with corresponding values filled in, the user can check if the form is valid by using $Form->isValid() Then he could get an array of errorous fields by using $Form->getInvalidFields() The rules use the following Syntax: o-method://(type)name="Default value" and (optionally) either a pcre-Regex with an leading / or a Validation function with a leading # o- is used if the Value is optional, than the Default value gets assigned if the the value is empty. method is one of the superglobal arrays without leading _, post/get/cookie ... (type) is optional and defines in which type the variable should be castet. As validation function any function could be used which is declared in the form's class. It uses #self::Functionname as syntax then. Planned features for the futur: - Various checks against xss, sql injection and other hacking attempts. - Add ability to use pear Validate class as a validator What do you think of it? Christian Sachs

« previous php.pear.dev (#25263) next »