Re: Form handling

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

on 06/10/2009 03:10 PM Eddie Drapkin said the following:
> 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
> error
>     public /* bool */ function setRequiredFieldTypes(array $fieldTypes);
> //array of field names => type a la ('username' => array(regex,
> '/a-zA-Z0-9\-_/'))
>                 //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
> error
>     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.
> 
> Thoughts?

You may want consider not reinventing the wheel.

I use this popular forms generation and validation class since about 10
years now. It can deal with pretty much all you need now and probably later.

http://www.phpclasses.org/formsgeneration

Here are some live examples of the class and its plug-ins.

http://www.meta-language.net/forms-examples.html

-- 

Regards,
Manuel Lemos

Find and post PHP jobs
http://www.phpclasses.org/jobs/

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux