PHP Classes

TM::Apeform: A very abstract web form builder and processor

Recommend this page to a friend!
  Info   Example   Screenshots   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStarStar 76%Total: 7,612 All time: 243 This week: 35Up
Version License PHP version Categories
apeform 1.0.0Free for non-comm...4.0.6HTML, Validation
Description 

Author

TM::Apeform creates self repeating web forms, so called "Affenformulare" (German for "ape forms"). If a million apes is typing into the form (that's the "Infinite monkey theorem"), the form is displayed again and again as long as it contains errors.

- The usage is not different from the creation, validation and processing of the form values that the user entered. Everything is done in a single script.
- The class hides the access to POST and global variables and simply returns the submitted values.
- It offers an easy way to handle input errors (checking valid email addresses for example).
- It supports all form elements including radio buttons, select boxes, file upload fields and so on.
- It provides an own templating system, so you do not have to deal with HTML at all.
- It creates labels and access keys according to HTML 4 standard and returns XHTML compatible output.
- In addition you can add JavaScript handlers to any form element.

TM::Apeform is optimized to be used with the minimum amount of source code. For example, the following script is a full functional form mailer.

<?php
require_once("Apeform.class.php");
$form = new Apeform();
$message = $form->textarea("Your Message");
$form->submit("Send Email");
$form->display();
if ($form->isValid()) mail("to@example.com", "Subject", $message);
?>

Picture of Thiemo Kreuz
  Performance   Level  
Name: Thiemo Kreuz <contact>
Classes: 2 packages by
Country: Germany Germany
Age: 47
All time rank: 27612 in Germany Germany
Week rank: 170 Up11 in Germany Germany Up
Innovation award
Innovation award
Nominee: 1x

Winner: 1x

Instructions

This class is written to use with PHP 4 and no longer works with newer PHP versions. So, please do not use it with newer PHP versions.

Example

<?php

/**
 * Email form example. Shows compatible use of select and radio. Shows basic
 * use of returning by reference. Shows use of acceskey characters.
 *
 * @author Thiemo Mättig (http://maettig.com/)
 */

require_once("Apeform.class.php");
$form = new Apeform();

$form->header("Support email");

// It's very easy to switch between input type "radio" and "select".
$problem = $form->select("Your <u>p</u>roblem", "", "I found 20 &euro;|I need help|It doesn't work");
$problem = $form->radio("Your <u>p</u>roblem", "", "I found 20 &euro;|I need help|It doesn't work");

// Return value as a reference, note the ampersand.
$description = &$form->textarea("<u>D</u>escribe your problem", "", "", 10);
// Due to the reference the following changes are displayed imediatelly.
$description = strtoupper($description);
if (!
$description)
{
   
$form->error("Description missing");
}

$form->header("Additional information about you");

$name = $form->text("Your <u>n</u>ame");
if (!
$name)
{
   
$form->error("Name missing");
}

// Return value as a reference, note the ampersand.
$email = &$form->text("Your <u>e</u>mail", "Please specify if you want an answer.");
// Add an individual class label to the form element above.
$form->addClass("important");
// Due to the reference the following changes are displayed imediatelly.
$email = strtolower(trim($email));
if (
$email && ! preg_match(
   
'/^[^\s"\'<>()@,;:]+@[^\s"\'<>()@,;:]+\.[a-z]{2,6}$/is', $email))
{
   
$form->error("Email invalid");
}

$form->submit("Send email");

echo
'<style type="text/css">';
echo
'table { margin: auto; }';
echo
'th { background-color: #D2ECD2; }';
echo
'td { background-color: #F4FAF4; }';
echo
'.important label, .important strong { background-color: #FE0; }';
echo
'</style>';

if (
$form->isValid())
{
   
// mail("example@example.com", $problem, $description, "From: $email");
   
echo "I'm trying to solve your problem. Please wait ...";
}

$form->display();

echo
'<p class="important"><strong>Important:</strong> Individual stylesheet class on single form elements.</p>';

?>


Screenshots (3)  
  • example_templates.png
  • example_advertisement.png
  • example_QuickForm_groups.png
  Files folder image Files (24)  
File Role Description
Accessible without login Plain text file Apeform.class.php Class Main class
Accessible without login HTML file Apeform_manual.html Doc. Manual and API reference
Accessible without login Plain text file ChangeLog.txt Doc. Change log
Accessible without login Plain text file example_accesskeys.php Example How to automatically create accesskey attributes
Accessible without login Plain text file example_advertisement.class.php Class Extended class with different templates
Accessible without login Plain text file example_advertisement.php Example Small advertisement form with an image upload
Accessible without login Plain text file example_colors.php Example Ideas for selecting a color in a form
Accessible without login Plain text file example_elements.class.php Class Extended class with special form elements
Accessible without login Plain text file example_elements.php Example How to use the special elements from the extended class
Accessible without login Plain text file example_email.php Example Small form mailer with error checking
Accessible without login Plain text file example_multiform.php Example How to use multiple forms on a single page
Accessible without login Plain text file example_multipage.php Example How to split a form into multiple pages
Accessible without login Plain text file example_multipage2.php Example How to split a form into multiple pages
Accessible without login Plain text file example_multiuse.php Example How to use a form multiple times
Accessible without login Plain text file example_QuickForm_elements.php Example Comparison with the features of PEAR::HTML_QuickForm
Accessible without login Plain text file example_QuickForm_groups.php Example Comparison with the features of PEAR::HTML_QuickForm
Accessible without login Plain text file example_regex_callback.php Example Extended validation methods with callbacks and regular expressions
Accessible without login Plain text file example_templates.php Example How to use different HTML and CSS templates
Accessible without login Plain text file example_tiny.php Example Basic textarea example
Accessible without login Plain text file example_tinymce.php Example How to use TinyMCE instead of a textarea
Accessible without login Plain text file test.php Test PHPUnit 1 unit test

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Reuses Unique User Downloads Download Rankings  
 0%1
Total:7,612
This week:0
All time:243
This week:35Up
 User Ratings  
 
 All time
Utility:87%StarStarStarStarStar
Consistency:87%StarStarStarStarStar
Documentation:81%StarStarStarStarStar
Examples:87%StarStarStarStarStar
Tests:75%StarStarStarStar
Videos:-
Overall:76%StarStarStarStar
Rank:58