NPODS - Donation System

Developer Examples

Simple Example

To begin go to the Download Page and download the latest version of the phplib library

Normally the only class that you will need to directly instanciate is the Form class this is found in form.class.php.Form an example of how the class works see the code snippet below.

First you instantiate the Form object and add any fields that will appear on the form.

<?php
/*
 * Include the Form class
 */
include_once("form.class.php");

/*
 * create a new instance of the Form object named myform with action="POST"
 */
$form = new Form("myform""POST");

/*
 * add two fields
 * 1) a text field called firstname
 * 2) a button called submit
 */
$form->addField("firstname""text");
$form->addField("submit""button");
?>

Next you include the form definition on all pages that use the form or form data including the html file that contains the form its self. A sample html form is provided below.

<?php
/*
 * Include the form definition file
 */
include("formdef.php");

/*
 * get form elements from $form object
*/
$firstname $form->getField("firstname");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html>
<head>
    <title>IIS Site Library</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<form name="<? echo $form->getName() ?>" method="post" action="processform.php">
  First Name
<input type="firstname" name="textfield" value="<? echo $firstname->getValue() ?>" /><br />
    <input type="submit" name="Submit" value="Submit" />
</form>
</body>
</html>

Lastly you get the form elements from the Form object and retrieve any necessary data.

<?php
/*
 * Include the form definition file
 */
include("formdef.php");

/*
 * get the firstname textfield from the form 
 * element and display its properties
 */
$textfield $form->getField("firstname");
echo 
$textfield->getValue() . "<br>";
echo 
$textfield->getName() . "<br>";
echo 
$textfield->getType() . "<br>";
echo 
$textfield->getMethod() . "<br><br>";

/*
 * get the submit button button from the form 
 * element and display its properties
 */
$textfield2 $form->getField("firstname");
echo 
$textfield2->getValue() . "<br>";
echo 
$textfield2->getName() . "<br>";
echo 
$textfield2->getType() . "<br>";
echo 
$textfield2->getMethod() . "<br>";
echo (
$textfield2->isClicked()) ? "Submit button clicked" "not clicked" "<br>";

?>

Files:

Other:

SourceForge.net Logo  Valid CSS!  spacerValid XHTML 1.0!