Reusable form elements with DB_Table and HTML_Quickforms
| From: | Matthew Vickery | Date: | Tue, 17 Oct 2006 09:49:33 +0000 |
| Subject: | Reusable form elements with DB_Table and HTML_Quickforms | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-25478@lists.php.net to get a copy of this message | ||
I have been experimenting with generating HTML forms and databases
using DB_Table and I think it is great!
I am often building several forms on the same Web server. Most of
these forms contain the same form elements, such as first name,
surname, email, addres_line1 etc.
It would be great if I could define a pool of reusable form elements
and then include or merge these into several form/database schemas.
I have tried this (see below), but not managed to succeed. Will someone
please point me in the right direction as I seem to be heading in the
wrong one!
Many thanks in advance,
Matthew
My pool of form elements:
// A class where I can define reusable form elements
class Elements_Pool extends DB_Table {
// id
var $id = array(
// unique row ID
'id' => array(
'type' => 'integer',
'require' => true
)
);
// Personal Details
var $personal_details = array(
// first name
'fname' => array(
'type' => 'varchar',
'size' => 32
),
// last name
'lname' => array(
'type' => 'varchar',
'size' => 64
),
// address line 1
'address_line1' => array(
'type' => 'varchar',
'size' => 64
)
)
// age
var $age= array(
// unique row ID
'age' => array(
'type' => 'integer',
'require' => true
)
);
}
// A class where I define the table schema for specific database/form
// and include only the elements that I need from the element pool
class Guestbook extends DB_Table {
var $col = array_merge(
$id,
$personal_details
);
}