HTML Class for PHP


/ Published in: PHP
Save to your folder(s)

A PHP class that creates html controls


Copy this code and paste it in your HTML
  1. <?
  2.  
  3. class HTML_DISPLAY
  4. {
  5. public function __construct($cols=3)
  6. {
  7. $this->tabCount = 0;
  8. $this->columns = $cols;
  9. }
  10. public function tableStart($border=0, $width="100%", $cellSpacing=2, $cellPadding=0)
  11. {
  12. if ($width != "")
  13. {
  14. $width = "width=\"$width\"";
  15. }
  16. if ($this->columns != 0)
  17. {
  18. $cols = "cols=\"$this->columns\"";
  19. }
  20. $this->tabRight();
  21. echo $this->printTabs()."<table border=\"$border\" $width cellpadding=\"$cellSpacing\" cellspacing=\"$cellPadding\">".$this->newLine;
  22. }
  23.  
  24. public function tableStop()
  25. {
  26. echo $this->printTabs()."</table>".$this->newLine ;
  27. $this->tabLeft();
  28. }
  29.  
  30. public function formStart($formName, $action="", $method="post", $target="")
  31. {
  32.  
  33. if ($target != "")
  34. {
  35. $target = "target=\$target\"";
  36. }
  37. $this->tabRight();
  38. $this->formName = $formName;
  39.  
  40. echo $this->printTabs()."<form name=\"$formName\" method=\"$method\" action=\"$action\" $target>".$this->newLine;
  41. }
  42.  
  43. public function formStop()
  44. {
  45. echo $this->printTabs()."</form>".$this->newLine;
  46. $this->tabLeft();
  47. }
  48.  
  49.  
  50. public function submitButton($type=1)
  51. {
  52. if ($type == 1)
  53. {
  54. $txt="Submit Answers";
  55. }
  56. elseif($type == 2)
  57. {
  58. $txt="Next ->";
  59. }
  60. else
  61. {
  62. $txt="Submit";
  63. }
  64. echo "<input type=\"submit\" name=\"$txt\" value=\"$txt\" />";
  65. }
  66.  
  67. public function clearButton()
  68. {
  69. echo "<input name=\"Clear\" type=\"Reset\" id=\"Clear\" value=\"Clear\" />";
  70. }
  71.  
  72. public function button($id, $display, $class="", $java="", $show=TRUE)
  73. {
  74. if ($class!= "")
  75. {
  76. $class = "class=\"$class\"";
  77. }
  78.  
  79. $buttonText = "<input type=\"button\" id=\"$id\" name=\"$id\" $class $java value=\"$display\"/>";
  80. if($show)
  81. {
  82. echo $buttonText;
  83. }
  84. else
  85. {
  86. return $buttonText;
  87. }
  88. }
  89.  
  90. public function hiddenField($div, $text="")
  91. {
  92. echo "<input id=\"$div\" type=\"hidden\" name=\"$div\" $text/>";
  93. }
  94.  
  95. public function rowStart($class="")
  96. {
  97. if ($class != "")
  98. {
  99. $class = " class=\"$class\"";
  100. }
  101.  
  102. $this->tabRight();
  103. echo $this->printTabs()."<tr $class>".$this->newLine;
  104. }
  105.  
  106. public function rowStop()
  107. {
  108. echo $this->printTabs()."</tr>".$this->newLine;
  109. $this->tabLeft();
  110. }
  111.  
  112. public function colStart($width, $colSpan=1, $rowSpan=1, $class=NULL)
  113. {
  114. $this->tabRight();
  115. $width = $width==""?$width:"width=\"$width%\"";
  116. echo $this->printTabs()."<td $width colspan=\"$colSpan\" rowspan=\"$rowSpan\" valign=\"top\" align=\"left\"";
  117.  
  118. if (!is_null($class))
  119. {
  120. echo " class=\"$class\"";
  121. }
  122. echo " >".$this->newLine;
  123. }
  124.  
  125. public function colStop()
  126. {
  127. echo $this->printTabs()."</td>".$this->newLine;
  128. $this->tabLeft();
  129. }
  130.  
  131. public function colHeaderStart($width, $colSpan=1, $rowSpan=1, $class=NULL)
  132. {
  133. $this->tabRight();
  134. echo $this->printTabs()."<th width=\"$width%\" colspan=\"$colSpan\" rowspan=\"$rowSpan\" valign=\"top\" ";
  135.  
  136. if (!is_null($class))
  137. {
  138. echo " class=\"$class\"";
  139. }
  140. echo " >".$this->newLine; }
  141.  
  142. public function colHeaderStop()
  143. {
  144. echo $this->printTabs()."</th>".$this->newLine;
  145. $this->tabLeft();
  146. }
  147.  
  148.  
  149.  
  150. public function insertRadioButton($divID, $radioText, $value="", $javaScript="", $showText=TRUE, $checked="")
  151. {
  152.  
  153. $textForFrontEnd = $radioText;
  154. if ($value=="")
  155. {
  156. $value=$radioText;
  157. }
  158.  
  159. if (!$showText)
  160. {
  161. $textForFrontEnd = "";
  162. }
  163.  
  164. $this->tabRight();
  165. echo $this->printTabs()."<label>".
  166. "<input name=\"$divID\" id=\"$divID\" type=\"radio\" value=\"$value\" $checked $javaScript>".
  167. "$textForFrontEnd</label>".$this->newLine;
  168. $this->tabLeft();
  169. }
  170.  
  171.  
  172.  
  173. public function dropDownListStart($divID, $javaScript=NULL)
  174. {
  175.  
  176. $this->tabRight();
  177. echo $this->printTabs()."<select id=\"$divID\" name=\"$divID\" $javaScript>".$this->newLine;
  178. $this->tabRight();
  179. }
  180.  
  181. public function dropDownListIetm ($value, $displayText, $selected="", $class=NULL)
  182. {
  183. echo $this->printTabs()."<option value=\"".strtoupper($value)."\" $selected ".
  184. ($class!=NULL?"class=\"$class\"":"").">$displayText</option>".$this->newLine;
  185.  
  186. }
  187.  
  188. public function dropDownListStop()
  189. {
  190. $this->tabLeft();
  191. echo $this->printTabs()."</select>".$this->newLine;
  192. $this->tabLeft();
  193. }
  194.  
  195.  
  196.  
  197.  
  198.  
  199. public function insertTextBox($div, $question, $charactersPerLine=25, $charLength=255, $text="", $multiline=FALSE, $password=FALSE)
  200. {
  201. $this->divArray[$this->formName][$div] =sizeof($this->divArray[$this->formName])+1;
  202.  
  203. if ($multiline)
  204. {
  205. //multi-line
  206. $strTextBox = "<textarea name=\"$div\" cols=\"$charactersPerLine\">$text</textarea>";
  207. }
  208. else
  209. {
  210. //single line
  211. $strTextBox = "<input name=\"$div\" id=\"$div\" type=\"text\" size=\"$charactersPerLine\" maxlength=\"$charLength\" $text/>";
  212. }
  213.  
  214. echo $strTextBox;
  215. }
  216.  
  217. public function insertPasswordBox($div, $charactersPerLine=25, $charLength=255)
  218. {
  219.  
  220. $strTextBox = "<input name=\"$div\" id=\"$div\" type=\"password\" size=\"$charactersPerLine\" maxlength=\"$charLength\"/>";
  221.  
  222. echo $strTextBox;
  223. }
  224.  
  225.  
  226. public function tabRight()
  227. {
  228. $this->tabCount++;
  229. }
  230.  
  231. public function tabLeft()
  232. {
  233. if ($this->tabCount > 0)
  234. {
  235. --$this->tabCount;
  236. }
  237. }
  238.  
  239. public function printTabs()
  240. {
  241. $tempTabs = "";
  242.  
  243. for ($i = 0; $i < $this->tabCount; ++$i)
  244. {
  245. $tempTabs .= $this->tab;
  246. }
  247.  
  248. return $tempTabs;
  249. }
  250.  
  251. public function linkTo($link, $linkText, $target="", $class="")
  252. {
  253. if ($target != "")
  254. {
  255. $target = "target=\"$target\"";
  256. }
  257. if ($class != "")
  258. {
  259. $class = "class=\"$class\"";
  260. }
  261.  
  262. echo "<a href=\"$link\" $target $class>$linkText</a>";
  263. }
  264.  
  265. public function divDisplayed()
  266. {
  267. /*
  268. echo "<br>";
  269. $pageKeys = array_keys($this->divArray);
  270. for ($i = 0; $i < sizeof($this->divArray); ++$i)
  271. {
  272. $page = $pageKeys[$i];
  273. $columnKeys = array_keys($this->divArray[$page]);
  274. for($j = 0; $j < sizeof($this->divArray[$page]); ++$j)
  275. {
  276. echo "$page|".$columnKeys[$j]."|".($j+1)."<br>";
  277. }
  278. }
  279. */
  280. }
  281.  
  282.  
  283. protected $newLine = "\n";
  284. protected $tab = "\t";
  285. protected $tabCount;
  286. protected $columns;
  287.  
  288.  
  289. protected $formName;
  290. protected $divArray;
  291. }
  292.  
  293. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.