PHPonTrax
[ class tree: PHPonTrax ] [ index: PHPonTrax ] [ all elements ]

Source for file form_tag_helper.php

Documentation is available at form_tag_helper.php

  1. <?php
  2. /**
  3. * File containing the FormTagHelper class and support functions
  4. *
  5. * (PHP 5)
  6. *
  7. * @package PHPonTrax
  8. * @version $Id$
  9. * @copyright (c) 2005 John Peterson
  10. *
  11. * Permission is hereby granted, free of charge, to any person obtaining
  12. * a copy of this software and associated documentation files (the
  13. * "Software"), to deal in the Software without restriction, including
  14. * without limitation the rights to use, copy, modify, merge, publish,
  15. * distribute, sublicense, and/or sell copies of the Software, and to
  16. * permit persons to whom the Software is furnished to do so, subject to
  17. * the following conditions:
  18. *
  19. * The above copyright notice and this permission notice shall be
  20. * included in all copies or substantial portions of the Software.
  21. *
  22. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  23. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  24. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  25. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  26. * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  27. * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  28. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  29. */
  30.  
  31. /**
  32. * @todo Document this class
  33. */
  34. class FormTagHelper extends Helpers {
  35.  
  36. /**
  37. * @todo Document this method
  38. */
  39. function form_tag($url_for_options = array(), $options = array()) {
  40. $html_options = array_merge(array("method" => "post"), $options);
  41.  
  42. if(array_key_exists('multipart',$html_options)
  43. && $html_options['multipart']) {
  44. $html_options['enctype'] = "multipart/form-data";
  45. unset($html_options['multipart']);
  46. }
  47.  
  48. $html_options['action'] = url_for($url_for_options);
  49. return $this->tag("form", $html_options, true);
  50. }
  51.  
  52. /**
  53. * @todo Document this method
  54. *
  55. */
  56. function start_form_tag() {
  57. $args = func_get_args();
  58. return call_user_func_array(array($this, 'form_tag'), $args);
  59. }
  60.  
  61. /**
  62. * @todo Document this method
  63. *
  64. */
  65. function select_tag($name, $option_tags = null, $options = array()) {
  66. return $this->content_tag("select", $option_tags, array_merge(array("name" => $name, "id" => $name), $this->convert_options($options)));
  67. }
  68.  
  69. /**
  70. * @todo Document this method
  71. *
  72. */
  73. function text_field_tag($name, $value = null, $options = array()) {
  74. return $this->tag("input", array_merge(array("type" => "text", "name" => $name, "id" => $name, "value" => $value), $this->convert_options($options)));
  75. }
  76.  
  77. /**
  78. * @todo Document this method
  79. *
  80. */
  81. function hidden_field_tag($name, $value = null, $options = array()) {
  82. return $this->text_field_tag($name, $value, array_merge($options, array("type" => "hidden")));
  83. }
  84.  
  85. /**
  86. * @todo Document this method
  87. *
  88. */
  89. function file_field_tag($name, $options = array()) {
  90. return $this->text_field_tag($name, null, array_merge($this->convert_options($options), array("type" => "file")));
  91. }
  92.  
  93. /**
  94. * @todo Document this method
  95. *
  96. */
  97. function password_field_tag($name = "password", $value = null, $options = array()) {
  98. return $this->text_field_tag($name, $value, array_merge($this->convert_options($options), array("type" => "password")));
  99. }
  100.  
  101. /**
  102. * @todo Document this method
  103. *
  104. */
  105. function text_area_tag($name, $content = null, $options = array()) {
  106. if ($options["size"]) {
  107. $size = explode('x', $options["size"]);
  108. $options["cols"] = reset($size);
  109. $options["rows"] = end($size);
  110. unset($options["size"]);
  111. }
  112.  
  113. return $this->content_tag("textarea", $content, array_merge(array("name" => $name, "id" => $name), $this->convert_options($options)));
  114. }
  115.  
  116. /**
  117. * @todo Document this method
  118. *
  119. */
  120. function check_box_tag($name, $value = "1", $checked = false, $options = array()) {
  121. $html_options = array_merge(array("type" => "checkbox", "name" => $name, "id" => $name, "value" => $value), $this->convert_options($options));
  122. if ($checked) $html_options["checked"] = "checked";
  123. return $this->tag("input", $html_options);
  124. }
  125.  
  126. /**
  127. * @todo Document this method
  128. *
  129. */
  130. function radio_button_tag($name, $value, $checked = false, $options = array()) {
  131. $html_options = array_merge(array("type" => "radio", "name" => $name, "id" => $name, "value" => $value), $this->convert_options($options));
  132. if ($checked) $html_options["checked"] = "checked";
  133. return $this->tag("input", $html_options);
  134. }
  135.  
  136. /**
  137. * @todo Document this method
  138. *
  139. */
  140. function submit_tag($value = "Save changes", $options = array()) {
  141. return $this->tag("input", array_merge(array("type" => "submit", "name" => "commit", "value" => $value), $this->convert_options($options)));
  142. }
  143.  
  144. /**
  145. *
  146. * @todo Document this method
  147. * @uses tag()
  148. */
  149. function image_submit_tag($source, $options = array()) {
  150. return $this->tag("input",
  151. array_merge(array("type" => "image",
  152. "src" => image_path($source)),
  153. $this->convert_options($options)));
  154. }
  155.  
  156. }
  157.  
  158. /**
  159. * @todo Document this method
  160. * Avialble functions for use in views
  161. */
  162. function form_tag() {
  163. $form_tag_helper = new FormTagHelper();
  164. $args = func_get_args();
  165. return call_user_func_array(array($form_tag_helper, 'form_tag'), $args);
  166. }
  167.  
  168. /**
  169. * @todo Document this method
  170. *
  171. */
  172. function start_form_tag() {
  173. $args = func_get_args();
  174. return call_user_func_array('form_tag', $args);
  175. }
  176.  
  177. /**
  178. * @todo Document this method
  179. *
  180. */
  181. function end_form_tag() {
  182. return "</form>";
  183. }
  184.  
  185. /**
  186. * @todo Document this method
  187. *
  188. */
  189. function select_tag() {
  190. $form_tag_helper = new FormTagHelper();
  191. $args = func_get_args();
  192. return call_user_func_array(array($form_tag_helper, 'select_tag'), $args);
  193. }
  194.  
  195. /**
  196. * @todo Document this method
  197. *
  198. */
  199. function text_field_tag() {
  200. $form_tag_helper = new FormTagHelper();
  201. $args = func_get_args();
  202. return call_user_func_array(array($form_tag_helper, 'text_field_tag'), $args);
  203. }
  204.  
  205. /**
  206. * @todo Document this method
  207. *
  208. */
  209. function hidden_field_tag() {
  210. $form_tag_helper = new FormTagHelper();
  211. $args = func_get_args();
  212. return call_user_func_array(array($form_tag_helper, 'hidden_field_tag'), $args);
  213. }
  214.  
  215. /**
  216. *
  217. * @todo Document this method
  218. */
  219. function file_field_tag() {
  220. $form_tag_helper = new FormTagHelper();
  221. $args = func_get_args();
  222. return call_user_func_array(array($form_tag_helper, 'file_field_tag'), $args);
  223. }
  224.  
  225. /**
  226. *
  227. * @todo Document this method
  228. */
  229. function password_field_tag() {
  230. $form_tag_helper = new FormTagHelper();
  231. $args = func_get_args();
  232. return call_user_func_array(array($form_tag_helper, 'password_field_tag'), $args);
  233. }
  234.  
  235. /**
  236. *
  237. * @todo Document this method
  238. */
  239. function text_area_tag() {
  240. $form_tag_helper = new FormTagHelper();
  241. $args = func_get_args();
  242. return call_user_func_array(array($form_tag_helper, 'text_area_tag'), $args);
  243. }
  244.  
  245. /**
  246. *
  247. * @todo Document this method
  248. */
  249. function check_box_tag() {
  250. $form_tag_helper = new FormTagHelper();
  251. $args = func_get_args();
  252. return call_user_func_array(array($form_tag_helper, 'check_box_tag'), $args);
  253. }
  254.  
  255. /**
  256. *
  257. * @todo Document this method
  258. */
  259. function radio_button_tag() {
  260. $form_tag_helper = new FormTagHelper();
  261. $args = func_get_args();
  262. return call_user_func_array(array($form_tag_helper, 'radio_button_tag'), $args);
  263. }
  264.  
  265. /**
  266. *
  267. * @todo Document this method
  268. */
  269. function submit_tag() {
  270. $form_tag_helper = new FormTagHelper();
  271. $args = func_get_args();
  272. return call_user_func_array(array($form_tag_helper, 'submit_tag'), $args);
  273. }
  274.  
  275. /**
  276. * @todo Document this method
  277. *
  278. */
  279. function image_submit_tag() {
  280. $form_tag_helper = new FormTagHelper();
  281. $args = func_get_args();
  282. return call_user_func_array(array($form_tag_helper, 'image_submit_tag'), $args);
  283. }
  284.  
  285. ?>

Documentation generated on Thu, 04 May 2006 19:47:43 -0600 by phpDocumentor 1.3.0RC4