[nycphp-talk] Custom Form Fields
Dan Cech
dcech at phpwerx.net
Fri Jan 30 10:39:24 EST 2004
Ophir Prusak wrote:
> Hi All,
>
> I've been tasked with a project that I think is applicable to almost
> every web based application:
> Giving the user the ability to add custom fields to their data / forms.
> After doing some thinking, I realized that the "engine" for such a
> feature could be totally generic and work for almost any web site.
> I looked on freshmeat, sourceforge and phpclasses but didn't see
> anything really geared toward this functionality.
>
> For example:
> Your client is a large car rental service and they wanted an intranet
> app that allows them to keep inventory of all their cars.
> Users enter make, model, color, year, A/C, miles, location, etc.
> After it's launched, the Dallas office wants to add a field for ground
> clearance (in inches) and four wheel drive (checkbox).
> The Miami office wants fields for Hitch (checkbox) and Engine Size
> (pulldown).
> You get the picture.
>
> What have you done or would you do when faced with this requirement ?
> Is this something you are in need of as well ?
> Comments / Suggestions ?
>
> I'm considering starting an open source project for this. I got an OK
> from my boss if it means other people will help out :).
> Are there other developers here who would be interested in joining a
> project like this ?
I haven't seen anything geared directly towards this, but it can
definitely be done.
The approach I like to take when building my applications is to try and
design all my database related code to be able to work with any number
of columns:
function load ($id)
{
$sql = 'SELECT * FROM mytable WHERE id=' $db->qstr ($id);
$rs = $db->SelectLimit ($sql,1);
if ( !is_object ($rs) )
{
return FALSE;
}
return $rs->FetchRow ();
}
That is a fairly basic example, but you see that you can simply add an
extra field in the database and it will automatically be added.
Another approach to this problem from a database perspective is to add a
table to hold these extra pieces of data, with columns id, att and val.
That gets a little more complicated in the load and save routines, but
is very good when you have extra data which is only applicable to a
small subset of your objects.
As for the forms, I did write an app a while ago which could generate
multipage forms from definitions stored in a database, which would allow
them to be edited through a web interface, that approach worked very
well for me, might even be able to dig up a copy if anyone is interested...
Dan
More information about the talk
mailing list