Source for file xhtml_forms.php

Documentation is available at xhtml_forms.php

  1. <?
  2.  
  3. /* Form selection menu*/
  4.  
  5. class selection_menu extends xml_element
  6. {
  7. function selection_menu($name,$initial_data=array(),$is_multiple="no")
  8. {
  9. $this->xml_element("select",array("name" => $name));
  10. if ($is_multiple=="yes") $this->set_attrib("multiple","yes");
  11. $this->build($initial_data);
  12. }
  13. function build($data)
  14. {
  15. foreach ($data as $name => $item)
  16. {
  17. if (is_array($item))
  18. {
  19. $submenu=&$this->add_submenu($name);
  20. $subment->build($item);
  21. }
  22. else
  23. {
  24. $this->add_option($name,$item);
  25. }
  26. }
  27. }
  28.  
  29. function &add_submenu($title)
  30. {
  31. $temp=&$this->add_child(new sub_menu($title),$title);
  32. return $temp;
  33. }
  34.  
  35. function add_option($label,$value="",$selected="no")
  36. {
  37. $temp=&$this->add_child(new selection_item($label,
  38. $value,
  39. $selected),
  40. $label);
  41. return $temp;
  42. }
  43.  
  44. }
  45.  
  46. /* Form submenu */
  47. class sub_menu extends selection_menu
  48. {
  49. function sub_menu($title)
  50. {
  51. $this->xml_element("optgroup",array("title" => $title));
  52. }
  53. }
  54. /* Form menu item */
  55. class selection_item extends xml_element
  56. {
  57. function selection_item($label,$value="",$selected="no")
  58. {
  59. $this->xml_element("option");
  60. $this->add_child($label);
  61. if ($value!="") $this->set_attrib("value",$value);
  62. if ($selected=="yes") $this->set_attrib("selected","yes");
  63. }
  64. }
  65.  
  66. class input_control extends xml_element
  67. {
  68. function input_control($type,$name,$value="",$label="")
  69. {
  70. $this->xml_element("label");
  71. $temp = new xml_element("input",array("name" => $name,
  72. "value" => $value,
  73. "type" => $type));
  74. $this->add_child($label);
  75. $this->add_child($temp,"control");
  76. }
  77. }
  78.  
  79. class text_input extends input_control
  80. {
  81. function text_input($name,$value="",$label="",$size=15)
  82. {
  83. $this->input_control("text",$name,$value,$label);
  84. $t=&$this->get_child("control");
  85. $t->set_attrib("size",$size);
  86. }
  87. }
  88.  
  89. class file_input extends input_control
  90. {
  91. function file_input($name,$value="",$label="")
  92. {
  93. $this->input_control("file",$name,$value,$label);
  94. }
  95. }
  96.  
  97.  
  98. class hidden_input extends input_control
  99. {
  100. function hidden_input($name,$value="")
  101. {
  102. $this->input_control("hidden",$name,$value);
  103. }
  104. }
  105.  
  106. class submit_input extends input_control
  107. {
  108. function submit_input($value="Submit")
  109. {
  110. $this->input_control("submit",$name,$value);
  111. }
  112. }
  113.  
  114.  
  115. class textarea extends xml_element
  116. {
  117. function textarea($name,$value,$label="",$rows="10",$cols="50")
  118. {
  119. $this->xml_element("label");
  120. $temp= new xml_element("textarea",array("rows" => $rows,
  121. "cols" => $cols,
  122. "name" => $name));
  123. $temp->add_child($value);
  124. $this->add_child($label);
  125. $this->add_child($temp);
  126. }
  127. }
  128.  
  129. class form extends xml_element
  130. {
  131. function form($action,$method="post",$enctype="application/x-www-form-encoded")
  132. {
  133. $this->xml_element("form",array("action" => $action,
  134. "method" => $method,
  135. "enctype" => $enctype));
  136. }
  137. }

Documentation generated on Tue, 24 May 2005 03:59:20 -0400 by phpDocumentor 1.3.0RC3