<?php

  require_once('HTML/QuickForm.php');
  require_once('HTML/QuickForm/Renderer/Xml.php');
  require_once('Var_Dump.php');

  class FrmTest extends HTML_QuickForm
  {
    function FrmTest()
    {
      $this->HTML_Quickform('formmoo');
 
      $this->addElement('text',   'moo', 'What sound does a cow make?:');
      
      $this->addElement('header', null, 'Choose shipping profile');
      $this->addElement('static', 'note', 'Note:', 'profiles \'foo\', \'bar\' and \'baz\' are considered existing');

      $this->addElement('radio',  'profile', null, 'Use existing profile', 'existing');
      $this->addElement('text',   'profileName', 'Profile name:', array('size' => 32, 'maxlength' => 32));

      $this->addElement('radio',  'profile', null, 'New personal profile', 'personal');
      $this->addElement('text',   'persProfileName', 'Profile name:', array('size' => 32, 'maxlength' => 32));
      $name[] =& $this->createElement('text', 'first', null, array('size' => 14, 'maxlength' => 100));
      $name[] =& $this->createElement('text', 'last', null, array('size' => 14, 'maxlength' => 100));
      $this->addGroup($name, 'persName', 'Name (first, last):', ' ');
      $this->addElement('text',   'persAddress', 'Address:', array('size' => 32, 'maxlength' => 255));

      $this->addElement('header', null, 'Choose Company profile');
      $this->addElement('radio',  'profile', null, 'New company profile', 'company');
      $this->addElement('text',   'compProfileName', 'Profile name:', array('size' => 32, 'maxlength' => 32));
      $this->addElement('text',   'compName', 'Company name:', array('size' => 32, 'maxlength' => 100));
      $this->addElement('text',   'compAddress', 'Address:', array('size' => 32, 'maxlength' => 255));
      $this->addElement('hidden', 'penguin', '1');
      $this->addElement('submit', null, 'Send');

      $this->addRule('compAddress', 'blaaa', 'required', null, 'client');
    }
  }

  $form = new FrmTest();
  $form->validate();
  $xml_dom = domxml_new_doc("1.0");
  $xml_root = $xml_dom->create_element("page");
  $xml_dom->append_child($xml_root);
  $xml_form = $xml_dom->create_element("test");
  $xml_root->append_child($xml_form);

  $renderer =& new HTML_QuickForm_Renderer_Xml(&$xml_dom, &$xml_form);
  $form->accept($renderer);
//  Var_Dump::display($renderer->toarray());
//  Var_Dump::display($renderer);

  
if (1 == 1)
{
  header("Content-Type: text/xml");
  echo $xml_dom->dump_mem();
/*  $dir = dirname(__FILE__);
  $xsl_stylesheet = domxml_xslt_stylesheet_file("$dir/main.xsl");
  $result = $xsl_stylesheet->process($xml_dom);
  print $xsl_stylesheet->result_dump_mem($result);
*/
}
else
{
  $form->display();
  echo "<pre>";
  echo htmlentities($xml_dom->dump_mem(true));
  echo "</pre>";
}


?>
