I have made a small API designed to simplify the retrieving an sanitizing of data from forms. Its at its early stages and I will probably change a lot in the next few weeks as I incorporate it into my one of my sites.
I descided to do this because I often found myself repeatedly consulting functions such as stripslashes, get_magic_quotes_gpc and setting form and form feild error messages. What this API allows, is one to define a form, each of its fields data types and the nullability of each field.
Each time a field is retrieved, it is casted to the data type set and any errors such as missing fields will throw an exception. The exception automatically sets a the forms/variables message and sets an error flag in the object. The feature I'll find most useful is the ability to get a prebuilt array in the form:
Array
(
[login] => Array
(
[submit] => Array
(
[value] => Logon
)
[username] => Array
(
[value] => user
)
[password] => Array
(
[value] =>
[msg] => This field cannot be left blank.
)
[age] => Array
(
[value] => 12
)
[msg] => Error While Processing Form
)
)
Where login is the form name, msg is the form message and all other elements are the form fields. This can then be used when displaying error responses and prefilling fields in the HTML.
Included in the ZIP file is a short example of how it is used. If anyone else finds it useful feel free to use it. If you have any suggestions of features to be added or find any bugs, just let me know.