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

Support This Project

Survey Style Form Example

Concept Familiarity

Rate your proficiency in the following areas where:
  • 1 = No familiarity
  • 2 = Newbie
  • 3 = Know the basics
  • 4 = Use it often
  • 5 = Expert
 12345
:
:
:
:
:
:
:

Software Experience





Opinion on Formitable



Formitable Referral

How did you learn about Formitable?





Personal Information

   

Thank you for completing the survey.
Survey results will be used to improve Formitable.


Code


/*** change the following variables ***/
$user = "user";
$pass = "pass";
$DB = "db";

require(
"../Formitable.class.php");

if(
strstr($_SERVER['SERVER_NAME'],"local")) $server="localhost";
else
$server="localhost";
$newForm = new Formitable( @mysql_connect("localhost",$user,$pass),$DB,"formitable_survey" );


$newForm->setPrimaryKey("ID");
//up the threshold for select instead of radio
$newForm->enumField_toggle=6;
//set all feedback messages to blank to handle manually
$newForm->msg_insertSuccess=$newForm->msg_insertFail=$newForm->msg_updateSuccess=$newForm->msg_updateFail="";

if( isset(
$_POST['submit']) ){

  if(
$newForm->submitForm() ){

    
//echo success
    
echo "<p class=\"centered\"><br>Thank you, ".ucfirst($_POST['first'])."<br><b>Your survey has been submitted.</b></p>";

  } else echo
"<p class=\"centered\">Survey Error. Please notify the Webmaster.";

} else {

  
$newForm->forceType("rate_other", "text");

  
$newForm->toggleFieldSets(false);

  
$newForm->normalizedField("state","states","Code","Name","Name ASC");

  
$newForm->getLabels("referral", "option_names");

  
$newForm->labelFields( array("first","last","referral","referral_other"),
                         array(
"First Name","Last Name", "How did you learn about Formitable?","") );

  
$newForm->labelField( "q1", "What development languages, platforms, and technologies do you currently use?" );
  
$newForm->labelField( "q2", "What technologies do you plan on using within the next year?" );
  
$newForm->labelField( "statement", "Will you use Formitable in your development?" );
  
$newForm->labelField( "comments", "How can Formitable be improved?" );

  
$newForm->labelField( "rate_q1", "PHP" );
  
$newForm->labelField( "rate_q2", "MySQL" );
  
$newForm->labelField( "rate_q3", "HTML Forms" );
  
$newForm->labelField( "rate_q4", "CSS" );
  
$newForm->labelField( "rate_q5", "Javascript" );
  
$newForm->labelField( "rate_q6", "Regular Expressions" );
  
$newForm->labelField( "rate_q7", "Other (describe below)" );
  
$newForm->labelField( "rate_other", "" );

  for(
$i=1;$i<=7;$i++) $newForm->getLabels("rate_q$i", "option_names");

}

?>
<? if( !isset($_POST['submit']) ): ?>
<? $newForm
->openForm(); $stdbrk=":</td><td>"; $blnkbrk="</td><td>"; $newForm->setFieldBreak(""); ?>
<table width="100%" bgcolor="#BDC0AE" cellpadding="0" cellspacing="1" align="center">
  <tr>
    <td>
      <table width="100%" bgcolor="#F2F4DF">
        <tr><td colspan=6><h3>Concept Familiarity</h3>
        Rate your proficiency in the following areas where:
        <ul><li>1 = No familiarity<li>2 = Newbie<li>3 = Know the basics<li>4 = Use it often<li>5 = Expert</ul></td></tr>
        <tr><td>&nbsp;</td><td align="center">1</td><td align="center">2</td><td align="center">3</td><td align="center">4</td><td align="center">5</td><td></td></tr>
        <tr><td colspan=6 height=1 bgcolor="black"></td></tr>
        <? $newForm->setLabelBreak(":</td><td align=\"center\">"); $newForm->setFieldBreak(""); $newForm->setOptionBreak("</td><td align=\"center\">"); ?>
        <tr><td><? $newForm->printField("rate_q1"); ?></td></tr>
        <tr><td><? $newForm->printField("rate_q2"); ?></td></tr>
        <tr><td><? $newForm->printField("rate_q3"); ?></td></tr>
        <tr><td><? $newForm->printField("rate_q4"); ?></td></tr>
        <tr><td><? $newForm->printField("rate_q5"); ?></td></tr>
        <tr><td><? $newForm->printField("rate_q6"); ?></td></tr>
        <tr><td><? $newForm->printField("rate_q7"); ?></td></tr>
        <tr><td colspan=6><? $newForm->setLabelBreak(""); $newForm->setFieldBreak(""); $newForm->printField("rate_other"); ?></td></tr>
      </table>
    </td>
  </tr>
  <tr>
    <td>
      <table width="100%" bgcolor="#F2F4DF">
        <tr><td><h3>Software Experience</h3></td></tr><? $newForm->setLabelBreak("<br>"); $newForm->setFieldBreak("<br>"); ?>
        <tr><td><? $newForm->printField("q1"); ?></td></tr>
        <tr><td><? $newForm->printField("q2"); ?></td></tr>
      </table>
    </td>
  </tr>
  <tr>
    <td>
      <table width="100%" bgcolor="#F2F4DF">
        <tr><td><h3>Opinion on Formitable</h3></td></tr>
        <tr><td><? $newForm->setFieldBreak(""); $newForm->printField("statement"); ?></td></tr>
        <tr><td><? $newForm->printField("comments"); ?></td></tr>
      </table>
    </td>
  </tr>
  <tr>
    <td>
      <table width="100%" bgcolor="#F2F4DF">
      <tr><td><h3>Formitable Referral</h3></td></tr>
        <tr><td><? $newForm->setLabelBreak("<br><br>"); $newForm->setFieldBreak(""); $newForm->setOptionBreak("<br>"); $newForm->printField("referral"); ?>
        <? $newForm->setLabelBreak(""); $newForm->printField("referral_other"); ?></td></tr>
      </table>
    </td>
  </tr>
  <tr>
    <td>
      <table width="100%" bgcolor="#F2F4DF">
        <tr><td colspan=2><h3>Personal Information</h3></td></tr>
        <tr><td width="133"><? $newForm->setLabelBreak($stdbrk); $newForm->printField("first"); ?></td></tr>
        <tr><td><? $newForm->printField("last"); ?></td></tr>
        <tr><td><? $newForm->printField("affiliation"); ?></td></tr>
        <tr><td><? $newForm->printField("email"); ?></td></tr>
        <tr><td><? $newForm->printField("city"); ?></td></tr>
        <tr><td><? $newForm->printField("state"); ?></td></tr>
        <tr><td><? $newForm->printField("country"); ?></td></tr>
        <tr><td><? $newForm->setOptionBreak("&nbsp;"); $newForm->printField("gender"); ?></td></tr>
      </table>
    </td>
  </tr>
  <tr>
    <td>
      <table width="100%" bgcolor="#F2F4DF">
        <tr><td align="center">
        <p>Thank you for completing the survey. Survey results will be used to improve Formitable.</p>
        <? $newForm->closeForm(); ?>
        </td></tr>
      </table>
    </td>
  </tr>
</table>

MySQL Tables

CREATE TABLE formitable_survey (
  ID smallint(4) unsigned NOT NULL auto_increment,
  first varchar(25) NOT NULL default '',
  last varchar(25) NOT NULL default '',
  affiliation varchar(70) NOT NULL default '',
  city varchar(50) NOT NULL default '',
  country varchar(25) NOT NULL default '',
  state enum('AK','AL','AR','AZ','CA','CO','CT','DC','DE','FL','GA','HI','IA','ID','IL','IN','KS','KY','LA','MA','MD',
    'ME','MI','MN','MO','MS','MT','NA','NC','ND','NE','NH','NJ','NM','NV','NY','OH','OK','OK','OR','PA','RI','SC','SD',
    'TN','TX','UT','VA','VT','WA','WI','WV','WY') NOT NULL default 'AK',
  email varchar(50) NOT NULL default '',
  gender enum('Female','Male') NOT NULL default 'Male',
  q1 text NOT NULL,
  q2 text NOT NULL,
  rate_q1 enum('1','2','3','4','5') NOT NULL default '1',
  rate_q2 enum('1','2','3','4','5') NOT NULL default '1',
  rate_q3 enum('1','2','3','4','5') NOT NULL default '1',
  rate_q4 enum('1','2','3','4','5') NOT NULL default '1',
  rate_q5 enum('1','2','3','4','5') NOT NULL default '1',
  rate_q6 enum('1','2','3','4','5') NOT NULL default '1',
  rate_q7 enum('1','2','3','4','5') NOT NULL default '1',
  rate_other tinytext,
  statement text NOT NULL,
  referral enum('site','flyer','colleague','newsletter','other_ref') NOT NULL default 'site',
  referral_other varchar(50) default NULL,
  comments text,
  PRIMARY KEY  (ID)
);


CREATE TABLE states (
  Name varchar(40) NOT NULL default '',
  Code char(2) NOT NULL default ''
);

INSERT INTO states VALUES (' Select a State', '');
INSERT INTO states VALUES ('Alabama', 'AL');
INSERT INTO states VALUES ('Alaska', 'AK');
INSERT INTO states VALUES ('Arizona', 'AZ');
INSERT INTO states VALUES ('Arkansas', 'AR');
INSERT INTO states VALUES ('California', 'CA');
INSERT INTO states VALUES ('Colorado', 'CO');
INSERT INTO states VALUES ('Connecticut', 'CT');
INSERT INTO states VALUES ('Delaware', 'DE');
INSERT INTO states VALUES ('Florida', 'FL');
INSERT INTO states VALUES ('Georgia', 'GA');
INSERT INTO states VALUES ('Hawaii', 'HI');
INSERT INTO states VALUES ('Idaho', 'ID');
INSERT INTO states VALUES ('Illinois', 'IL');
INSERT INTO states VALUES ('Indiana', 'IN');
INSERT INTO states VALUES ('Iowa', 'IA');
INSERT INTO states VALUES ('Kansas', 'KS');
INSERT INTO states VALUES ('Kentucky', 'KY');
INSERT INTO states VALUES ('Louisiana', 'LA');
INSERT INTO states VALUES ('Maine', 'ME');
INSERT INTO states VALUES ('Maryland', 'MD');
INSERT INTO states VALUES ('Massachusetts', 'MA');
INSERT INTO states VALUES ('Michigan', 'MI');
INSERT INTO states VALUES ('Minnesota', 'MN');
INSERT INTO states VALUES ('Mississippi', 'MS');
INSERT INTO states VALUES ('Missouri', 'MO');
INSERT INTO states VALUES ('Montana', 'MT');
INSERT INTO states VALUES ('Nebraska', 'NE');
INSERT INTO states VALUES ('Nevada', 'NV');
INSERT INTO states VALUES ('New Hampshire', 'NH');
INSERT INTO states VALUES ('New Jersey', 'NJ');
INSERT INTO states VALUES ('New Mexico', 'NM');
INSERT INTO states VALUES ('New York', 'NY');
INSERT INTO states VALUES ('North Carolina', 'NC');
INSERT INTO states VALUES ('North Dakota', 'ND');
INSERT INTO states VALUES ('Ohio', 'OH');
INSERT INTO states VALUES ('Oklahoma', 'OK');
INSERT INTO states VALUES ('Oregon', 'OR');
INSERT INTO states VALUES ('Pennsylvania', 'PA');
INSERT INTO states VALUES ('Puerto Rico', 'PR');
INSERT INTO states VALUES ('Rhode Island', 'RI');
INSERT INTO states VALUES ('South Carolina', 'SC');
INSERT INTO states VALUES ('South Dakota', 'SD');
INSERT INTO states VALUES ('Tennessee', 'TN');
INSERT INTO states VALUES ('Texas', 'TX');
INSERT INTO states VALUES ('Utah', 'UT');
INSERT INTO states VALUES ('Vermont', 'VT');
INSERT INTO states VALUES ('Virgin Islands', 'VI');
INSERT INTO states VALUES ('Virginia', 'VA');
INSERT INTO states VALUES ('Washington', 'WA');
INSERT INTO states VALUES ('West Virginia', 'WV');
INSERT INTO states VALUES ('Wisconsin', 'WI');
INSERT INTO states VALUES ('Wyoming', 'WY');


CREATE TABLE option_names (
  ID varchar(25) NOT NULL default '',
  name tinytext NOT NULL,
  PRIMARY KEY  (ID)
);

INSERT INTO option_names VALUES ('other', 'Other (describe below):');
INSERT INTO option_names VALUES ('1', '');
INSERT INTO option_names VALUES ('2', '');
INSERT INTO option_names VALUES ('3', '');
INSERT INTO option_names VALUES ('4', '');
INSERT INTO option_names VALUES ('5', '');
INSERT INTO option_names VALUES ('site', 'SourceForge');
INSERT INTO option_names VALUES ('flyer', 'PHP Classes Site');
INSERT INTO option_names VALUES ('newsletter', 'Article or Email');
INSERT INTO option_names VALUES ('colleague', 'Another Developer');
INSERT INTO option_names VALUES ('other_ref', 'Other (please specify below)');