Sample 2. The bounded-draw output.

    1. Fast and easy customizable.

   View LIVE DEMO on this sample   BACK to Examples Page

Show Plain Text »
  1. <?php
  2.   // Please include automatic loading of classes for proper on-demand-loading of
  3.   // necessary DataForm classes
  4.   function __autoload($class)
  5.   {
  6.     $class = strtolower($class);
  7.     if(eregi("df_", $class) == true)
  8.     {
  9.       include("classes/".$class.".php");
  10.     }
  11.   }
  12.  
  13.   // Create Main instance of DataForm
  14.   $DataForm = new df_main();
  15.  
  16.   // Output your desired preset design this will automaticly add the responding
  17.   // classes to your bounded elements in addition to your eventually preset ones
  18.   $DataForm->setDesign("beach");
  19.  
  20.   // Create our first Form add self as action if you want the target to be the page itself
  21.   $mainform = new df_form("mainform", "output.php", false, NULL, "POST", "myform", "My first Form");
  22.  
  23.   // Binding the Form to the main DataForm instance
  24.   $DataForm->bindForm($mainform);
  25.  
  26.   // We will add here an extra css class which combines with the design preset class
  27.   // Creating an instance of an Element
  28.   // Way 1:
  29.   $elem = new df_textbox("prim_txt", NULL, "A simple Value", "First:", "my_special_textbox");
  30.  
  31.   // Setting HTML right before that element
  32.   $elem->setHTMLBefore("<br />");
  33.  
  34.   // Binding Elements to existing forms.
  35.   // Way 1:
  36.   $mainform->bindElement($elem);
  37.  
  38.   // By default all bounded elements will be drawn, when the master-form is beeing drawn.
  39.   // If you want to output it manually, like we will see later in this file
  40.   // you can avoid bounded_draw like follows, or simply dont bind it to any form :-)
  41.   $newelem = new df_textbox("exotic", NULL, "I am exotic", "Exotic:");
  42.   $newelem->setBoundedDraw(false);
  43.   $mainform->bindElement($newelem);
  44.  
  45.   // Binding Elements to existing forms
  46.   // Way 2:
  47.   $mainform->bindElement(new df_textbox("second_txt", NULL, "Another value", "Second:"));
  48.   $elem->setHTMLAfter("<br />");
  49.   $mainform->bindElement(new df_textarea("mytextarea", NULL,
  50.     "This has <b>some</b> <i>bad</i> <b>html</b> inside <badtag>javascript:alert(\"Im evil\");</badtag>",
  51.     "MyBox:",
  52.     "mytextareadesign"));
  53.  
  54.   // This way you create and bind dropdowns Options-> 2d-Array -> inner one looks this way:
  55.   // 1. Value, 2. Display
  56.   // or
  57.   // 1. optgroupname with no more params
  58.   // dont forget to close the optgroup with a single paramed array with "END"
  59.  
  60.   $dpvalue = array(
  61.     //Optiongroup APPHP
  62.     array("APPHP"),
  63.     array("1", "PHP DataGrid"),
  64.     array("2", "PHP Easy Installer"),
  65.     array("3", "PHP Admin Panel"),
  66.     array("4", "JS Auto From Validator"),
  67.     array("END"),
  68.     //Optiongroup Links
  69.     array("Links"),
  70.     array("php.net", "PHP.NET"),
  71.     array("apphp.com", "APPHP.COM"),
  72.     array("softic.at", "softic.at"),
  73.     array("END"),
  74.     //Define Elements nongrouped
  75.     array("t1", "Ungrouped1"),
  76.     array("t2", "Ungrouped2"),
  77.     array("t3", "Ungrouped3")
  78.   );
  79.   $mydp = new df_dropdown("mydp", "mydp", $dpvalue, "MyDP:");
  80.   $mydp->setHTMLAfter("<br />");
  81.   $mainform->bindElement($mydp);
  82.  
  83.   // Now comes a group of radioboxes
  84.   $radio1 = new df_radio("male", "male", "m", "Male:", true, "gender");
  85.   $radio2 = new df_radio("female", "female", "f", "Female:", false, "gender");
  86.   $radio2->setHTMLAfter("<br />");
  87.   $mainform->bindElement($radio1);
  88.   $mainform->bindElement($radio2);
  89.  
  90.   // Lets add some Checkboxes
  91.   $chk1 = new df_checkbox("check1", "check1", "first", "Like PHP?", true);
  92.   $chk2 = new df_checkbox("check2", "check2", "second", "Like ASP?", false);
  93.   $mainform->bindElement($chk1);
  94.   $mainform->bindElement($chk2);
  95.  
  96.   // Adding now a very secret password field
  97.   $mainform->bindElement(new df_password("secret", "secret", NULL, "Secret:"));
  98.  
  99.   // Now a neat little IMAGE Button
  100.   $mainform->bindElement(new df_image("./images/php-powered.gif", "phppow", "phppow"));
  101.  
  102.   // We are going to send along with this Form a hidden field
  103.   $mainform->bindElement(new df_hidden("ghost", "ghost", "I am a ghost"));
  104.  
  105.   // What about a fileupload element
  106.   $file = new df_file("fileup", NULL, NULL, "File:");
  107.   $file->setHTMLBefore("<br /><br />");
  108.   $file->setHTMLAfter("<br /><br />");
  109.   $mainform->bindElement($file);
  110.  
  111.   // Here we are going to define a submit button and a reset button
  112.   $mainform->bindElement(new df_submit("Submit", NULL, "Submit"));
  113.   $mainform->bindElement(new df_reset("btn_reset", NULL, "Reset"));
  114.  
  115.   // Bound Elements have references to their Forms
  116.   $name = $elem->getForm()->getName();
  117.  
  118.   // Create your HTML Header
  119.   ## Output the set Designset
  120.   echo $DataForm->includeMoo();
  121.   echo $DataForm->getDesign();
  122.  
  123.   // Output the whole creation
  124.   echo $DataForm->output();
  125.  
  126.   echo "<h3>Now comes the handbuild part</h3>";
  127.  
  128.   // Output our element, which has deactivated Bound-Draw
  129.   echo $newelem->draw();       
  130.   // If the element was not instanced on creation
  131.   // you can search the bounded form for that element.
  132.   // Search is done first by ID then by NAME tags
  133.   echo "<br />";
  134.   echo $mainform->getBoundElement("second_txt")->draw();
  135.  
  136. ?>