PHP Classes

File: example/sample.php

Recommend this page to a friend!
  Classes of Daniel McFeeters   FiForms Framework   example/sample.php   Download  
File: example/sample.php
Role: Example script
Content type: text/plain
Description: Extended example script
Class: FiForms Framework
Framework for rapid Web application development
Author: By
Last change: Made Accessible without user login.
Date: 19 years ago
Size: 5,059 bytes
 

Contents

Class file image Download
<?php
 
// Sample script for FiForms

  // This php script illustrates how to make a web form
  // based on a MySQL database table. Look through this script
  // to get an idea how to use FiForms.
  // To start with, you may want to just copy this file and
  // modify its contents to generate your own forms. Or just
  // get some ideas from it and then write your own FiForms.
  // First off, we need to include the main FiForms PHP file

 
require_once("FiForms_FiForm.inc.php"); // call the include file

  // Then we need to declare a new form, give it a
  // name (for the HTML form), and tell it how to
  // connect with the database

 
$frm = new FiForm(
     
"SampleForm", // Form Name
     
"FiForms_sample", // Database
     
"addressbook" // Table Name
     
);

 
// There are a lot of options on the form we can change
  // e.g. we can specify the exact SQL query used in the form
  // like this:

  // $frm->dataQuery = "SELECT FirstName, LastName, City from addressbook";

  // We can change the caption at the top of the page like this:
 
$frm->caption = "FiForms Sample Data Entry Form";

 
// Or we can disable navigation on the form like this:
  // $frm->noNavigation = TRUE;

  // Now we need to put input boxes onto the form. We need to create
  // iInputs as elements of the inputs[] array. There are several ways
  // to do this, depending on the amount of control we need to have
  // over the appearance of the form.
  // If we want, we can just tell FiForms to generate
  // inputs for all the fields in the table. This is the
  // quickest way to generate a form.

 
$frm->autoinputs();

 
// Of course, there's always at least one field we'd rather
  // the user didn't see, so we hide it like this.

 
$frm->eraseIn('addressID');
 
$frm->eraseIn('Notes');

 
// Now we'll change the caption on one of the boxes
 
$frm->renameIn('SSNo','Social Security #');

 
// Actually, we'll just erase this one, on second thought
 
$frm->eraseIn('SSNo');

 
// If you don't want to automatically generate iInputs, or you want to
  // override the automatic settings, you can declare them individually,
  // like this:

 
$frm->inputs["Birthday"] =
         new
iDateText // override an existing iText input with an
                    // iDateText input
    
("Birthday", // Field Name
    
"Birthday"); // Caption

  // A shorthand way to do this would be to use the addIn function, like this:

  // $frm->addIn('iDateText','Birthday','Birthday');

  // The first parameter is the class of the input. The remaining parameters
  // are passed to the constructor of that input. The Field Name is used as
  // the array key.

  // There are a number of different types of iInput. Here is an
  // example using the iDBSelect, and html select or drop-down
  // box filled with data from an SQL query

 
$frm->addIn('iDBSelect','State','','SELECT * FROM states;');

 
// We only want to show the following controls in normal view
  // (hide them in sheetView)
 
if($frm->sheetView == FALSE)
  {
 
// Here is an example of an iTextArea. This is similar to iText,
  // only it uses a <textarea> tag to specify a block of text input
 
$frm->addIn('iTextArea','Notes','',60,5);

 
// Link to a subform
 
$frm->addIn(
     
'iSubform',
     
'sample_subform.php', // PHP Script File
     
'Family Members', // Caption
     
'addrid=%addressID%', // criteria
     
600, // width
     
230 // height
     
);

 
// enable Sheet View in subform
 
$frm->inputs["sample_subform.php"]->params = "sheetView=YES";
 
 
// Note in the above example that, even though we used the addIn function
  // to create the subform, we can still reference it as an element
  // of the inputs[] array. The array index is always the second parameter
  // passed to the addIn function

  // Now just for fun, let's add a button link back to the index page
  // that opens in a popup window
 
$frm->addIn(
     
'iLink',
     
'../index.html',
     
'Home Page',
     
'homewindow',
     
'menubar=no,status=no,toolbar=no,width=750,height=550,scrollbars=yes',
     
'button',
     
'Go To Home...'
     
);

 
// Add a link to allow the user to view the report.
 
$frm->addIn('iLink','sample_FiReport.xml','Preview Report');

  }
// if sheetView == FALSE
 
  // The following line insures that the user can click back to normal view
  // after entering SheetView mode
 
$frm->addIn('iLinkBack');

 
// At this point, all of the inputs are defined. If we need to do more
  // server-side checking or processing of the data, this is the place
  // to do it.
 
 
if($frm->inputs['Name']->valueToSave == "John Doe")
  {
    
$frm->throwError(
        
'John Doe, can\'t you think of a better name?');
  }
 
 
// Finally, output the entire page to the client
 
echo $frm->drawFormPage(); // output the form

?>