Просмотр файла engine/classes/form.class.php

Размер файла: 4.84Kb
  1. <?
  2. class form {
  3. public $form = '';
  4. public $act;
  5. public $method;
  6. public $formname;
  7. public $hiden = array();
  8. public $formid;
  9. public $legend;
  10. public $enctype;
  11.  
  12. function __construct($act, $method = '', $name = '',$enctype = '', $id = '', $hidden = '', $legend = '') {
  13. $this -> act = $act;
  14. $this -> method = $method ? $method : 'post';
  15. $this -> name = $name ? $name : '';
  16. $this -> id = $id ? $id : '';
  17. $this -> hidden = $hidden ? $hidden : '';
  18. $this -> legend = $legend ? $legend : '';
  19. $this -> enctype = $enctype ? $enctype : '';
  20. $form = '<form '.$this->enctype.' action="' . $this->act . '" method="' . $this->method . '" ';
  21. $form .= $this->id ? 'id="' . $this->id . '" ' : '';
  22. $form .= $this->name ? 'name="' . $this->name . '">' : '>';
  23. return $this -> form = $form . PHP_EOL;
  24. }
  25. /*
  26. * Форма form input
  27. * <input type="text" name="name">
  28. * $form->input('Название','name','type','value',true) Стандартный стиль.
  29. */
  30. function input($text = '', $name, $type = 'text', $value = '',$post = '', $size = 20,$br = true, $max = '', $names = '', $readonly = 0,$radio_id = false) {
  31.  
  32. $form = '';
  33. $form .= $text ? $text .'<br/>' : '';
  34. $form .= '<input type="' . $type . '" name="' . $name . '" id="'.$radio_id.'" value="' . $value . '" "'.$value2.'" size="' . $size . '" ';
  35. $form .= $readonly ? 'readonly="readonly" ' : '';
  36. $form.= $max ? 'maxlength="' . $max . '" />'.($br ? '<br />' : null).'' : '/> '.$names.''.($br ? '<br />' : null).'';
  37. $form .= $post ? $post : '';
  38. return $this->form .= PHP_EOL . $form . PHP_EOL;
  39. }
  40.  
  41. function input2($text = '', $name, $type = 'text',$value = '',$value2 = '',$names = '',$br = true) {
  42. $form = '';
  43. $form .= $text ? $text .'<br/>' : '';
  44. $form .= '<input type="' . $type . '" name="' . $name . '" value="' . $value . '"' . $value2 . '/>&nbsp;'.$names.'' .($br ? '<br />' : null);
  45. return $this->form .= PHP_EOL . $form . PHP_EOL;
  46. }
  47. function input3($text = '', $name, $type = 'text',$value = '',$value2 = '',$names = '') {
  48. $form = '';
  49. $form .= $text ? $text .'' : '';
  50. $form .= '<input type="' . $type . '" name="' . $name . '" value="' . $value . '"' . $value2 . '/>&nbsp;'.$names.'';
  51. return $this->form .= PHP_EOL . $form . PHP_EOL;
  52. }
  53. function textarea ($text = '', $name, $value = '',$post = '', $readonly = 0) {
  54. $form = '';
  55. $form .= $text ? '' . $text . '<br/>' : '';
  56. $form .= '<textarea id="editor" class="lined" name="' . $name . '"' . ($readonly ? 'readonly="readonly"' : '') . '>';
  57. $form .= $value ? $value : '';
  58. $form .= '</textarea><br/>';
  59. $form .= $post ? $post : '';
  60. return $this->form .= PHP_EOL . $form . PHP_EOL;
  61. }
  62.  
  63. function select ($text, $name, $param, $selected = 1,$optgroup = false, $optgroup2 = false,$style = false) {
  64. if (!is_array($param)) {
  65. $form = '';
  66. } else {
  67. $form = ($text ? '' . $text . '<br/>' : null) . '<select name="' . $name . '" '.$multi.'>' . PHP_EOL;
  68. $form .= $optgroup;
  69. $x = 1;
  70. foreach ($param as $k => $v) {
  71. $form .= '<option '.$style.' value="' . $v . '" ' . ($x==$selected ? 'selected="selected"' : '') . '>' . $k . '</option>' . PHP_EOL;
  72. $x ++;
  73. }
  74. $form .= $optgroup2;
  75. $form .= '</select><br/>';
  76. }
  77. return $this->form .= $form . PHP_EOL;
  78. }
  79. public function text($text) {
  80. $form = $text;
  81. return $this->form .= $form . PHP_EOL;
  82. }
  83. public function select2($text,$name,$select,$from,$value,$option) {
  84. global $db;
  85. $form = ($text ? $text . '<br/>' : null) . '<select name="' . $name . '">' . PHP_EOL;
  86. $selecting = $db->query("SELECT $select FROM `$from`");
  87. while($selects = $db->get_array($selecting)) {
  88. $form.= '<option value="'.$selects[$value].'">'.$selects[$option].'</option>';
  89. }
  90. $form.= '</select><br/>';
  91. return $this->form .= $form . PHP_EOL;
  92. }
  93. //Функция для работы с input type="radio"
  94. //Может выводит 2 radio не больше!
  95. public function html_radio($label, $name, $values){
  96. $form = $label.'<br />';
  97. foreach($values as $key => $value){
  98. $form .= '<input type="radio" name="'.$name.'" value="'.$key.'"><label for="xforward_matching_yes">'.$value.'</label>&nbsp;&nbsp;';
  99. }
  100. return $this->form .= $form . PHP_EOL;
  101. }
  102.  
  103. function submit ($value = 'Отправить',$name = 'submit', $br = false,$class = 'Button') {
  104. $form = '<input class="'.$class.'" type="submit" name="' . $name . '" value="' . $value . '" />' .($br ? '<br />' : null);
  105. return $this->form .= $form . PHP_EOL;
  106.  
  107. }
  108. function display() {
  109. echo $this -> form . '</form>';
  110. }
  111. }
  112.  
  113.  
  114.  
  115. ?>