<?php
// Please include automatic loading of classes for proper on-demand-loading of
// necessary DataForm classes
function __autoload($class)
{
$class = strtolower($class);
if(eregi("df_", $class) == true)
{
include("classes/".$class.".php");
}
}
// Create Main instance of DataForm
$DataForm = new df_main();
// Output your desired preset design this will automaticly add the responding
// classes to your bounded elements in addition to your eventually preset ones
$DataForm->setDesign("beach");
// Create our first Form add self as action if you want the target to be the page itself
$mainform = new df_form("mainform", "output.php", false, NULL, "POST", "myform", "My first Form");
// Binding the Form to the main DataForm instance
$DataForm->bindForm($mainform);
// We will add here an extra css class which combines with the design preset class
// Creating an instance of an Element
// Way 1:
$elem = new df_textbox("prim_txt", NULL, "A simple Value", "First:", "my_special_textbox");
// Setting HTML right before that element
$elem->setHTMLBefore("<br />");
// Binding Elements to existing forms.
// Way 1:
$mainform->bindElement($elem);
// By default all bounded elements will be drawn, when the master-form is beeing drawn.
// If you want to output it manually, like we will see later in this file
// you can avoid bounded_draw like follows, or simply dont bind it to any form :-)
$newelem = new df_textbox("exotic", NULL, "I am exotic", "Exotic:");
$newelem->setBoundedDraw(false);
$mainform->bindElement($newelem);
// Binding Elements to existing forms
// Way 2:
$mainform->bindElement(new df_textbox("second_txt", NULL, "Another value", "Second:"));
$elem->setHTMLAfter("<br />");
$mainform->bindElement(new df_textarea("mytextarea", NULL,
"This has <b>some</b> <i>bad</i> <b>html</b> inside <badtag>javascript:alert(\"Im evil\");</badtag>",
"MyBox:",
"mytextareadesign"));
// This way you create and bind dropdowns Options-> 2d-Array -> inner one looks this way:
// 1. Value, 2. Display
// or
// 1. optgroupname with no more params
// dont forget to close the optgroup with a single paramed array with "END"
$dpvalue = array(
//Optiongroup APPHP
array("APPHP"),
array("1", "PHP DataGrid"),
array("2", "PHP Easy Installer"),
array("3", "PHP Admin Panel"),
array("4", "JS Auto From Validator"),
array("END"),
//Optiongroup Links
array("Links"),
array("php.net", "PHP.NET"),
array("apphp.com", "APPHP.COM"),
array("softic.at", "softic.at"),
array("END"),
//Define Elements nongrouped
array("t1", "Ungrouped1"),
array("t2", "Ungrouped2"),
array("t3", "Ungrouped3")
);
$mydp = new df_dropdown("mydp", "mydp", $dpvalue, "MyDP:");
$mydp->setHTMLAfter("<br />");
$mainform->bindElement($mydp);
// Now comes a group of radioboxes
$radio1 = new df_radio("male", "male", "m", "Male:", true, "gender");
$radio2 = new df_radio("female", "female", "f", "Female:", false, "gender");
$radio2->setHTMLAfter("<br />");
$mainform->bindElement($radio1);
$mainform->bindElement($radio2);
// Lets add some Checkboxes
$chk1 = new df_checkbox("check1", "check1", "first", "Like PHP?", true);
$chk2 = new df_checkbox("check2", "check2", "second", "Like ASP?", false);
$mainform->bindElement($chk1);
$mainform->bindElement($chk2);
// Adding now a very secret password field
$mainform->bindElement(new df_password("secret", "secret", NULL, "Secret:"));
// Now a neat little IMAGE Button
$mainform->bindElement(new df_image("./images/php-powered.gif", "phppow", "phppow"));
// We are going to send along with this Form a hidden field
$mainform->bindElement(new df_hidden("ghost", "ghost", "I am a ghost"));
// What about a fileupload element
$file = new df_file("fileup", NULL, NULL, "File:");
$file->setHTMLBefore("<br /><br />");
$file->setHTMLAfter("<br /><br />");
$mainform->bindElement($file);
// Here we are going to define a submit button and a reset button
$mainform->bindElement(new df_submit("Submit", NULL, "Submit"));
$mainform->bindElement(new df_reset("btn_reset", NULL, "Reset"));
// Bound Elements have references to their Forms
$name = $elem->getForm()->getName();
// Create your HTML Header
## Output the set Designset
echo $DataForm->includeMoo();
echo $DataForm->getDesign();
// Output the whole creation
echo $DataForm->output();
echo "<h3>Now comes the handbuild part</h3>";
// Output our element, which has deactivated Bound-Draw
echo $newelem->draw();
// If the element was not instanced on creation
// you can search the bounded form for that element.
// Search is done first by ID then by NAME tags
echo "<br />";
echo $mainform->getBoundElement("second_txt")->draw();
?>