Source for file formsgen.php

Documentation is available at formsgen.php

  1. <?php
  2. class InputForm {
  3. var $options = array();
  4.  
  5. var $_rows;
  6. var $_hiddens;
  7.  
  8. var $_elements = array(
  9. 'hidden' => '<input type="hidden" name="%1" value="%2" />',
  10. 'file' => '<input type="file" name="%1" value="" />',
  11. );
  12.  
  13. function InputForm($action = '', $method = 'get', $submit = 'Submit', $reset = '', $target = '', $enctype = '', $name = '', $events = '') {
  14. $this->options = array(
  15. 'action' => $action,
  16. 'method' => $method,
  17. 'target' => $target,
  18. 'enctype' => $enctype,
  19. 'events' => $events,
  20. 'submit' => $submit,
  21. 'name' => $name,
  22. 'reset' => $reset,
  23. );
  24. }
  25.  
  26. function addrow($title, $contents = '', $valign = 'middle', $align = 'left') {
  27. @list( $talign, $calign ) = explode( ",", $align );
  28. if ( empty( $calign ) ) $calign = $talign;
  29. @list( $tvalign, $cvalign ) = explode( ",", $valign );
  30. if ( empty( $cvalign ) ) $cvalign = $tvalign;
  31. $this->_rows[]=array(
  32. 'title' => $title,
  33. 'contents' => $contents,
  34. 'title_valign' => $tvalign,
  35. 'content_valign' => $cvalign,
  36. 'title_align' => $talign,
  37. 'content_align' => $calign
  38. );
  39. end($this->_rows);
  40. return key($this->_rows);
  41. }
  42.  
  43. function hidden($name, $value) {
  44. $this->_hiddens[$name] = $value;
  45. }
  46.  
  47. function addbreak($break = "&nbsp;") {
  48. $this->_rows[] = array('break' => $break);
  49. end($this->_rows);
  50. return key($this->_rows);
  51. }
  52.  
  53. function addmessage( $message ){
  54. $this->_rows[]=array("message"=>$message);
  55. }
  56.  
  57.  
  58. function show($return = false) {
  59. $result = '<form action="' . $this->options['action'] . '" method="' . $this->options['method'] . '" name="' . $this->options['name'] . '"';
  60. if(!empty($this->options['target'])) {
  61. $result .= ' target="' . $this->options['target'] . '"';
  62. }
  63. if(!empty($this->options['enctype'])) {
  64. $result .= ' enctype="' . $this->options['enctype'] . '"';
  65. }
  66. if(!empty($this->options['events'])) {
  67. $result .= ' ' . $this->options['events'];
  68. }
  69. $result .= '>' . "\n";
  70.  
  71. if(is_array($this->_hiddens)) {
  72. foreach($this->_hiddens as $name => $value){
  73. $result .= str_replace(array('%1', '%2'), array($name, $value), $this->_elements['hidden']) . "\n";
  74. }
  75. }
  76.  
  77. $result .= '<table border="0" cellspacing="2" cellpadding="2" width="100%">' . "\n";
  78.  
  79. if(is_array($this->_rows)) {
  80. foreach($this->_rows as $key=>$row){
  81. if(!empty($row['break'])){
  82. $result .= '<tr>' . "\n";
  83. $result .= ' <th colspan="2">' . $row['break'] . '</td>' . "\n";
  84. $result .= '</tr>' . "\n";
  85. } elseif(!empty($row['message'])){
  86. $result .= '<tr>' . "\n";
  87. $result .= ' <td colspan="2" class="row1">' . $row['message'] . '</td>' . "\n";
  88. $result .= '</tr>' . "\n";
  89. } else {
  90. $result .= '<tr>' . "\n";
  91. $result .= ' <td valign="' . $row['title_valign'] . '" align="' . $row['title_align'] . '" class="row2" ' . ((empty($row['contents'])) ? ' colspan="2"' : '') . '>' . $row['title'] . '</td>' . "\n";
  92. if(!empty($row['contents'])){
  93. $result .= ' <td valign="' . $row['title_valign'] . '" align="' . $row['title_align'] . '" class="row3">' . $row['contents'] . '</td>' . "\n";
  94. }
  95. $result .= '</tr>' . "\n";
  96. }
  97. }
  98. }
  99. $result .= '<tr>' . "\n";
  100. $result .= ' <td align="center" colspan="2"><input type="submit" value="' . $this->options['submit'] . '" class="btnmain">';
  101. if(!empty($this->options['reset'])) {
  102. $result .= '<input type="reset" value="' . $this->options['reset'] . '" class="btnlite">';
  103. }
  104. $result .= '</td>' . "\n";
  105. $result .= '</tr>' . "\n";
  106. $result .= '</table>' . "\n";
  107. $result .= '</form>' . "\n";
  108. if($return){
  109. return $result;
  110. } else {
  111. echo $result;
  112. return true;
  113. }
  114. }
  115.  
  116. function text_box($name, $value, $size = 0, $maxlength = 0, $password = false, $extra = ''){
  117. return '<input type="' . (($password) ? 'password' : 'text') . '" class="text" name="' . $name . '"' . (($size > 0) ? ' size="' . $size . '"' : '') . (($maxlength > 0) ? ' maxlength="' . $maxlength . '"' : '') . ' value="' . htmlspecialchars($value) . '" ' . $extra . '>';
  118. }
  119.  
  120. function textarea($name, $value, $cols = 30, $rows = 5, $extra = ''){
  121. return '<textarea name="' . $name . '" cols="' . $cols . '" rows="' . $rows . '" ' . $extra . '>' . htmlspecialchars($value) . '</textarea>';
  122. }
  123.  
  124. function select_tag($name, $values, $selected = '', $extra = ''){
  125. $data = '<select name="' . $name . '" ' . $extra . '>' . "\n";
  126. foreach($values as $value => $text){
  127. $data .= '<option value="' . $value . '" ' . (($selected == $value) ? 'selected' : '') . '>' . __($text) . '</option>' . "\n";
  128. }
  129. $data .= '</select> ' . "\n";
  130. return $data;
  131. }
  132.  
  133. function radio_button($name, $values, $selected = '', $separator = ' ', $extra = ''){
  134. $data = '';
  135. foreach($values as $value => $text){
  136. $id = rcms_random_string(5);
  137. $data .= '<input type="radio" name="' . $name . '" value="' . $value . '" id="' . $id . '" ' . (($selected == $value) ? 'checked' : '') . ' ' . $extra . '><label for="' . $id . '">' . $text . '</label>' . $separator;
  138. }
  139. return $data;
  140. }
  141.  
  142. function radio_button_single($name, $value, $selected = '', $caption = ' ', $extra = ''){
  143. $id = rcms_random_string(5);
  144. return '<input type="radio" name="' . $name . '" value="' . $value . '" id="' . $id . '" ' . (($selected) ? 'checked' : '') . ' ' . $extra . '><label for="' . $id . '">' . $caption . '</label>';
  145. }
  146.  
  147. function checkbox($name, $value, $caption, $checked = 0, $extra = ''){
  148. $id = rcms_random_string(5);
  149. return '<input type="checkbox" name="' . $name . '" value="' . $value . '" id="' . $id . '" ' . ((!empty($checked)) ? 'checked' : '') . ' ' . $extra . ' /><label for="' . $id . '">' . $caption . '</label>';
  150. }
  151.  
  152. function file($name) {
  153. return '<input type="file" name="' . $name . '" value="" />';
  154. }
  155. }
  156. ?>

Documentation generated on Fri, 08 Jun 2007 12:21:24 +0300 by phpDocumentor 1.3.0RC3