n. 1. the inherit form in every MySQL table. 2. the php script that makes it happen.

Support This Project

The Original Formitable Example

Also try retrieving a record.













Favorite Foods








Favorite Day














Code

<?PHP

//include class, create new Formitable, set primary key field name
include("Formitable.class.php");
$newForm = new Formitable( mysql_connect("server","user","pass"),"db","table" );

$newForm->setPrimaryKey("ID");

//call submit method if form has been submitted
if( isset($_POST['submit']) ) $newForm->submitForm();

//otherwise continuing with form customizations
else {
    
    
//retrieve a record for update if GET var set
    
if( isset($_GET['ID']) ) $newForm->getRecord($_GET['ID']);
    
    
//hide primary key field, force a few field types
    
$newForm->hideField("ID");
    
$newForm->forceTypes(array("foods","day_of_week"),array("checkbox","radio"));

    
//get data pairs from another table
    
$newForm->normalizedField("toon","formitable_toons","ID","name","pkey ASC");
    
    
//set custom field labels
    
$newForm->labelFields( array("f_name","l_name","description","pets","foods","color","day_of_week","b_day","toon"),
                         array(
"First Name","Last Name","About Yourself","Your Pets","Favorite Foods","Favorite Color","Favorite Day","Your Birthday","Favorite Cartoon") );

    
//output form
    
$newForm->printForm();

}

?>

MySQL Tables

CREATE TABLE formitable_demo (
  ID tinyint(3) unsigned NOT NULL auto_increment,
  f_name varchar(50) default NULL,
  l_name varchar(50) default NULL,
  description text,
  pets set('Dog','Cat','Fish','Horse','Frog','Rodent','Reptile','None') default NULL,
  foods set('pizza','pasta','salad','sandwich','hamburger') default NULL,
  color enum('Red','Blue','Green','Purple','Yellow','Other') default NULL,
  day_of_week enum('Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday') default NULL,
  b_day date default NULL,
  toon tinyint(3) unsigned NOT NULL default '1',
  PRIMARY KEY  (ID)
) TYPE=MyISAM;


CREATE TABLE formitable_toons (
  ID tinyint(3) unsigned NOT NULL auto_increment,
  name tinytext NOT NULL,
  PRIMARY KEY  (ID)
) TYPE=MyISAM;

INSERT INTO formitable_toons VALUES (1, 'The Simpsons');
INSERT INTO formitable_toons VALUES (2, 'The Flinstones');
INSERT INTO formitable_toons VALUES (3, 'Dexter\'s Lab');
INSERT INTO formitable_toons VALUES (4, 'Power Puff Girls');
INSERT INTO formitable_toons VALUES (5, 'The Jetsons');
INSERT INTO formitable_toons VALUES (6, 'Family Guy');
INSERT INTO formitable_toons VALUES (7, 'Scooby Doo');
INSERT INTO formitable_toons VALUES (8, 'Other');