PHP Classes
Icontem

File: example_QuickForm_elements.php


  Search   All class groups All class groups   Latest entries Latest entries   Top 10 charts Top 10 charts   Newsletter Newsletter   Blog Blog   Forums Forums   Help FAQ Help FAQ  
  Login   Register  
Recommend this page to a friend! ReTweet ReTweet Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Thiemo Mättig  >  TM::Apeform  >  example_QuickForm_elements.php  
File: example_QuickForm_elements.php
Role: Example script
Content type: text/plain
Description: Comparison with the features of PEAR::HTML_QuickForm
Class: TM::Apeform
A very abstract web form builder and processor
 

Contents

Class file image Download
<?php

/**
 * Example for TM::Apeform (compare with PEAR::HTML_QuickForm's "elements"
 * example).
 *
 * @author Thiemo Mättig (http://maettig.com/)
 */

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

$form->templates['header'] =
    
"<tr>\n<th colspan=\"2\" class=\"header\">{header}</th>\n</tr>\n";
$form->templates['input'] = "<tr>\n<th align=\"right\" valign=\"top\">{label}" .
    
"</th>\n<td valign=\"top\">{error}{input}{help}</td>\n</tr>\n";
$form->templates['error'] = "<div class=\"error\">{error}</div>\n";
echo 
'<style type="text/css">';
echo 
'.header{background-color:#CCC;text-align:left;}';
echo 
'sup{color:#F00;}';
echo 
'.error{color:#F00;}';
echo 
'</style>';

$form->header("Normal Elements");
$data['ihidTest'] = $form->hidden("hiddenField");
$data['itxtTest'] = $form->text("<sup>*</sup>Test <u>T</u>ext""",
    
"Test Text Box");
if (! 
$data['itxtTest'])
{
    
$form->error("Test Text is a required field");
}
$data['itxaTest'] = $form->textarea("<sup>*</sup>Test T<u>e</u>xtArea""",
    
"Hello World");
if (! 
$data['itxaTest'])
{
    
$form->error("Test TextArea is a required field");
}
elseif (
strlen($data['itxaTest']) < 5)
{
    
$form->error("Test TextArea must be at least 5 characters");
}
$data['ipwdTest'] = $form->password("Test <u>P</u>assword");
if (
$data['ipwdTest'] &&
    (
strlen($data['ipwdTest']) < || strlen($data['ipwdTest']) > 10))
{
    
$form->error("Password must be between 8 to 10 characters");
}

// $data['ifilTest'] = $form->file("File");
$data['ichkTest'] = $form->checkbox("Test CheckBox""",
    
"C<u>h</u>eck the box",
    
"C<u>h</u>eck the box");
$data['iradTest'] = $form->radio("Test Radio Buttons""",
    array(
        
"Check the radio button #<u>1</u><br>",
        
"Check the radio button #<u>2</u>"),
    
0);
$data['ibtnTest'] = $form->submit("Test Button");
$data['isubTest'] = $form->submit("Test Submit");
$data['iimgTest'] = $form->image("http://pear.php.net/gifs/pear-icon.gif");
$data['iselTest'] = $form->select("Test Se<u>l</u>ect""""A|B|C|D""B"5);

$form->header("Custom Elements");
$data['dateTest1'] = $form->text("<u>D</u>ate1""""11.01.2003"011);
$data['dateTest2'] = $form->text("<u>D</u>ate2""""01. Januar 2001 00:00",
    
22);
$data['dateTest3'] = $form->staticText("Today is"""date("l, d M Y"));

$options = array(
    
"Pop / Belle & Sebastian",
    
"Pop / Elliot Smith",
    
"Pop / Beck",
    
"Rock / Noir Desir",
    
"Rock / Violent Femmes",
    
"Classical / Wagner",
    
"Classical / Mozart",
    
"Classical / Beethoven");
$data['ihsTest'] = $form->select("Hierarchical select"""$options);

$data['iadvChk'] = $form->checkbox("Advanced checkbox",
    
"This is a standard checkbox.", array('on' => "Check the box"));

$data['iautoComp'] = $form->text("Your favourite fruit",
    
"This is a standard text element."""030);

$form->header("Grouped Elements");

$data['name'] = $form->text("Na<u>m</u>e (last, first)""\t, ", array("Daniel""Adam"), 0, array(3020));
$data['phoneNo'] = $form->text("Teleph<u>o</u>ne""\t-\t-",
    array(
"513""123""3456"), array(334), array(445));
$data['iradYesNo'] = $form->radio("Yes/No""",
    
"<u>Y</u>es|<u>N</u>o",
    
"<u>Y</u>es");
$data['ichkABC'] = $form->checkbox("ABC""",
    
"<u>A</u><br>|<u>B</u><br>|<u>C</u>",
    
"<u>A</u><br>|<u>B</u><br>");

$form->submit("Submit|Test Button""<sup>*</sup> denotes required field");

if (
$form->isValid())
{
    echo 
"<pre>";
    
var_dump($data);
    echo 
"</pre>";
    echo 
"<hr>";
}

$form->display();

?>

 
  Advertise on this site Advertise on this site   Site map Site map   Statistics Statistics   Site tips Site tips   Privacy policy Privacy policy   Contact Contact  

For more information send a message to :
info at phpclasses dot org.
Copyright (c) Icontem 1999-2009 PHP Classes - PHP Class Scripts
  PHP Book Reviews - Reviews of books and other products