I've been charged with writing a class that handles forms, once they've been
POSTed to.  The idea of the class is to handle the most common use-cases of
POST forms, and any special functionality can be handled with a child class
at a later date, but for our uses, we're going to have mostly pretty typical
POST forms.  Follows is the list of cases I've determined that are the most
common, can anyone think of any that are omitted or that are never going to
be used?

class form_handler {
    public /* bool */ function setRequiredFields(array $fields); //takes a
simple array that corresponds to a $_POST key, verifying that there is data
on required fields but not for optional fields, returns true or false on
    public /* bool */ function setRequiredFieldTypes(array $fieldTypes);
//array of field names => type a la ('username' => array(regex,
                //or 'phone_number' => (array('int', 'min_len' => 7,
'max_len' => 10)) etc, the exact spec is obviously nowhere near done but
will probably just wrap a lot of filter_ functions, returns true or false on
    public /* string */ function validateAndCaptureError(); //returns error
or empty string
    public /* void */ function validateAndForwardTo($page); //forwards to
page on error, or not

each of the globule setters will have a corresponding appendRequired...
method, so as not to require handling enormous data structures for
conditional form building.
As you can see, the class looks pretty barren, but I can't think of any more
functionality than would be required, although I am kickign the idea around
of having very specific validation type methods ie.
form_handler::requireInt($field, array $options) or
form_handler::requireRegex($field, $regex), etc.


Thanks in advance,

Reply via email to