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

Support This Project

Time Example














Code

<?PHP

include("Formitable.class.php");
$newForm = new Formitable( mysql_connect("server","user","pass"),"db","formitable_time" );

//set some default values
$newForm->setDefaultValue("day",date("l",(time() + (24 * 60 * 60))),true);
$newForm->setDefaultValue("time",date("H:i:s",(time() + (2 * 60 * 60))),true);
$newForm->setDefaultValue("date",date("Y/m/d",(time() + (31 * 24 * 60 * 60))),true);
$newForm->setDefaultValue("year",date("Y",(time() - (36 * 365 * 24 * 60 * 60))),true);
$newForm->setDefaultValue("timestamp",date("YmdHis",(time() + (4 * 365 * 24 * 60 * 60))),true);

//set up regular expressions for field validation
$newForm->registerValidation("required",".+","Input is required.");
$newForm->registerValidation("year_range","(19[8-9][0-9])|20[0-1][0-9]","Enter a valid year (1980-2019).");
$newForm->registerValidation("this_month",date("Y/m/")."[0-2][0-9]|[3][0-1]","Enter a day in this month.");

//set fields for validation using regexs above
$newForm->validateField("timestamp","required");
$newForm->validateField("year","year_range");
$newForm->validateField("date","this_month");

//output form if not submitted or there were errors on submit
if( !isset($_POST['submit']) ||
    (isset(
$_POST['submit']) && $newForm->submitForm() == -1) ){

    
$newForm->openForm();
    
$newForm->printField("day");
    
$newForm->printField("time");
    
$newForm->printField("date");
    
$newForm->printField("year");
    
$newForm->printField("timestamp");
    
$newForm->closeForm();

}


?>

MySQL Table

CREATE TABLE formitable_time (
  `ID` tinyint(3) unsigned NOT NULL auto_increment,
  `time` time NOT NULL default '00:00:00',
  `timestamp` timestamp(14) NOT NULL,
  `date` date NOT NULL default '0000-00-00',
  `year` year(4) NOT NULL default '0000',
  PRIMARY KEY  (`ID`)
);