Login   Register  
PHP Classes
elePHPant
Icontem

File: example_multiuse.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Thiemo Mättig  >  TM::Apeform  >  example_multiuse.php  >  Download  
File: example_multiuse.php
Role: Example script
Content type: text/plain
Description: How to use a form multiple times
Class: TM::Apeform
A very abstract web form builder and processor
Author: By
Last change: Accessible without user login
Date: 5 years ago
Size: 940 bytes
 

Contents

Class file image Download
<?php

/**
 * Single page, multiple use form example. Shows use of a single form to
 * acquire multiple database records.
 *
 * @author Thiemo Mättig (http://maettig.com/)
 */

// Include the class.
require_once("Apeform.class.php");
// Create an instance of the class.
$form = new Apeform();

// Add some form elements. Note the ampersands (get the values as references).
$name = &$form->text("Name");
// Do some basic error handling.
if (! $name$form->error("Name missing");
$age = &$form->text("Age""\tYears"02);
if (
$age 1$form->error("Age missing");
$form->submit("Insert Record");

if (
$form->isValid())
{
    
// Process the database query (dummy code in this example, of course).
    
echo "INSERT INTO table SET name = '$name', age = '$age'";
    
// Reset the form elements (that's the trick to empty the form).
    
$name "";
    
$age 0;
}

// Display the form.
$form->display();

?>