home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 June / ENTER.ISO / files / xampp-win32-1.4.5-installer.exe / xampp / FlexyDynamic_example.php < prev    next >
Encoding:
PHP Script  |  2004-03-24  |  3.6 KB  |  112 lines

  1. <?php
  2. /**
  3.  * Example of usage for HTML_QuickForm Object renderer
  4.  * with Flexy template engine and dynamic template
  5.  *
  6.  * @author Ron McClain <mixtli@cats.ucsc.edu>
  7.  *
  8.  * $Id: FlexyDynamic_example.php,v 1.2 2003/11/03 12:55:53 avb Exp $ 
  9.  */
  10.  
  11. require_once 'HTML/QuickForm.php';
  12. require_once 'HTML/QuickForm/Renderer/Object.php';
  13. require_once 'HTML/Template/Flexy.php';
  14.  
  15. $form = new HTML_QuickForm('frmTest', 'post');
  16.  
  17. $form->setDefaults(array(
  18.     'itxtTest'  => 'Test Text Box',
  19.     'itxaTest'  => 'Hello World',
  20.     'iselTest'  => array('B', 'C'),
  21.     'name'      => array('first' => 'Thomas', 'last' => 'Schulz'),
  22.     'iradYesNo' => 'Y',
  23.     'ichkABCD'  => array('A'=>true,'D'=>true)
  24. ));
  25.  
  26. $form->addElement('header', '', 'Normal Elements');
  27.  
  28. $form->addElement('hidden', 'ihidTest', 'hiddenField');
  29.  
  30. $form->addElement('text', 'itxtTest', 'Test Text');
  31.  
  32. $form->addElement('textarea', 'itxaTest', 'Test TextArea');
  33.  
  34. // will be later assigned to style green
  35. $form->addElement('password', 'ipwdTest', array('Test Password', 'Please choose a password which is hard to guess'));
  36. $select =& $form->addElement('select', 'iselTest', 'Test Select', array('A'=>'A', 'B'=>'B','C'=>'C','D'=>'D'));
  37. $select->setSize(5);
  38. $select->setMultiple(true);
  39.  
  40. $form->addElement('submit', 'isubTest', 'Test Submit');
  41.  
  42. $form->addElement('header', '', 'Grouped Elements');
  43.  
  44. $checkbox[] = &HTML_QuickForm::createElement('checkbox', 'A', null, 'A');
  45. $checkbox[] = &HTML_QuickForm::createElement('checkbox', 'B', null, 'B');
  46. $checkbox[] = &HTML_QuickForm::createElement('checkbox', 'C', null, 'C');
  47. $checkbox[] = &HTML_QuickForm::createElement('checkbox', 'D', null, 'D');
  48. $form->addGroup($checkbox, 'ichkABCD', 'ABCD', '<br />');
  49.  
  50. // will be later assigned to style fancygroup
  51. $radio[] = &HTML_QuickForm::createElement('radio', null, null, 'Yes', 'Y');
  52. $radio[] = &HTML_QuickForm::createElement('radio', null, null, 'No', 'N');
  53. $form->addGroup($radio, 'iradYesNo', 'Yes/No');
  54.  
  55. // will be later assigned to style fancygroup
  56. $name['first'] = &HTML_QuickForm::createElement('text', 'first', 'First:');
  57. $name['first']->setSize(20);
  58. $name['last'] = &HTML_QuickForm::createElement('text', 'last', 'Last:');
  59. $name['last']->setSize(30);
  60. $form->addGroup($name, 'name', 'Name');
  61.  
  62. // add some 'required' rules to show "stars" and (possible) errors...
  63. $form->addRule('itxtTest', 'Test Text is a required field', 'required');
  64. $form->addRule('itxaTest', 'Test TextArea is a required field', 'required');
  65. $form->addGroupRule('iradYesNo', 'Check Yes or No', 'required');
  66. $form->addGroupRule('name', array('last' => array(array('Last name is required', 'required'))));
  67.  
  68. // try to validate the form
  69. if ($form->validate()) {
  70.     $form->freeze();
  71. }
  72.  
  73. $renderer =& new HTML_QuickForm_Renderer_Object(true);
  74.  
  75. // give some elements aditional style informations
  76. $renderer->setElementStyle(array(
  77.     'ipwdTest'  => 'green',
  78.     'iradYesNo' => 'fancygroup',
  79.     'name'      => 'fancygroup'
  80. ));
  81.  
  82. $form->accept($renderer);
  83.  
  84.  
  85. $options = &PEAR::getStaticProperty('HTML_Template_Flexy','options');
  86. $options = array(
  87.     'templateDir' => './templates',
  88.     'compileDir' => './templates/build',
  89.     'debug' => 0
  90. );
  91. $tpl =& new HTML_Template_Flexy($options);
  92.  
  93. //$tpl->compile("styles/green.html");
  94. //$tpl->compile("styles/fancygroup.html");
  95.  
  96. // assign array with form data
  97. $view = new StdClass;
  98. $view->form = $renderer->toObject();
  99.  
  100. // capture the array stucture 
  101. // (only for showing in sample template)
  102. ob_start();
  103. print_r($renderer->toObject());
  104. $view->dynamic_object =  ob_get_contents();
  105. // XXX: dunno how to make Flexy ignore the placeholder
  106. $view->formdata = '{formdata}';
  107. ob_end_clean();
  108.  
  109. // render and display the template
  110. $tpl->compile('flexy-dynamic.html');
  111. $tpl->outputObject($view);
  112. ?>