lib.form.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. # ***** BEGIN LICENSE BLOCK *****
  3. # This file is part of DotClear.
  4. # Copyright (c) 2004 Olivier Meunier and contributors. All rights
  5. # reserved.
  6. #
  7. # DotClear is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # DotClear is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with DotClear; if not, write to the Free Software
  19. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. #
  21. # ***** END LICENSE BLOCK *****
  22. class form
  23. {
  24. function combo($name,$arryData,$default='',$class='',$id='',$tabindex='')
  25. {
  26. $res = '<select name="'.$name.'" ';
  27. if($class != '')
  28. $res .= 'class="'.$class.'" ';
  29. if($tabindex != '')
  30. $res .= 'tabindex="'.$tabindex.'" ';
  31. if($id != '')
  32. $res .= 'id="'.$id.'" ';
  33. else
  34. $res .= 'id="'.$name.'" ';
  35. $res .= '>'."\n";
  36. foreach($arryData as $k => $v)
  37. {
  38. $res .= '<option value="'.$v.'"';
  39. if($v == $default)
  40. $res .= ' selected="selected"';
  41. $res .= '>'.$k.'</option>'."\n";
  42. }
  43. $res .= '</select>'."\n";
  44. return $res;
  45. }
  46. function radio($name, $value, $checked='', $class='', $id='')
  47. {
  48. $res = '<input type="radio" name="'.$name.'" value="'.$value.'" ';
  49. if($class != '') {
  50. $res .= 'class="'.$class.'" ';
  51. }
  52. if($id != '') {
  53. $res .= 'id="'.$id.'" ';
  54. }
  55. if (($checked === 0) or $checked >= 1) {
  56. $res .= 'checked="checked" ';
  57. }
  58. $res .= '/>'."\n";
  59. return $res;
  60. }
  61. function checkbox($name, $value, $checked='', $class='', $id='')
  62. {
  63. $res = '<input type="checkbox" name="'.$name.'" value="'.$value.'"';
  64. if($class != '')
  65. $res .= 'class="'.$class.'" ';
  66. if($id != '') {
  67. $res .= 'id="'.$id.'" ';
  68. }
  69. if($checked != '') {
  70. $res.='checked="checked"';
  71. }
  72. $res .= ' />'."\n";
  73. return $res;
  74. }
  75. function field($id,$size,$max,$default='',$tabindex='',$html='')
  76. {
  77. if (is_array($id)) {
  78. $name = $id[0];
  79. $id = isset($id[1]) ? $id[1] : '';
  80. } else {
  81. $name = $id;
  82. }
  83. $res = '<input type="text" size="'.$size.'" name="'.$name.'" ';
  84. $res .= ($id != '') ? 'id="'.$id.'" ' : '';
  85. $res .= ($max != '') ? 'maxlength="'.$max.'" ' : '';
  86. $res .= ($tabindex != '') ? 'tabindex="'.$tabindex.'" ' : '';
  87. $res .= ($default != '') ? 'value="'.$default.'" ' : '';
  88. $res .= $html;
  89. $res .= ' />';
  90. return $res;
  91. }
  92. function textArea($id,$cols,$rows,$default='',$tabindex='',$html='')
  93. {
  94. $res = '<textarea cols="'.$cols.'" rows="'.$rows.'" ';
  95. $res .= 'name="'.$id.'" id="'.$id.'" ';
  96. $res .= ($tabindex != '') ? 'tabindex="'.$tabindex.'" ' : '';
  97. $res .= $html.'>';
  98. $res .= $default;
  99. $res .= '</textarea>';
  100. return $res;
  101. }
  102. function hidden($id,$value)
  103. {
  104. return '<input type="hidden" name="'.$id.'" value="'.$value.'" />';
  105. }
  106. }
  107. ?>