Page 1 of 1

Reusable form elements with DB_Table and HTML_Quickforms

Posted: Tue Oct 17, 2006 4:02 am
by mattvick
Hi There,

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:

Code: Select all

// 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
       )
   );
}
My Table / form schema

Code: Select all

// 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
   );

}