View file engine/classes/form.class.php

File size: 4.78Kb
<?
class form {
	public $form = ''; 
	public $act; 
	public $method; 
	public $formname; 
	public $hiden = array(); 
	public $formid; 
	public $legend; 
	public $enctype;

	function __construct($act, $method = '', $name = '',$enctype = '', $id = '', $hidden = '', $legend = '') {
		$this -> act = $act; 
		$this -> method = $method ? $method : 'post'; 
		$this -> name = $name ? $name : ''; 
		$this -> id = $id ? $id : ''; 
		$this -> hidden = $hidden ? $hidden : ''; 
		$this -> legend = $legend ? $legend : ''; 
		$this -> enctype = $enctype ? $enctype : '';
			$form = '<form '.$this->enctype.' action="' . $this->act . '" method="' . $this->method . '" '; 
		$form .= $this->id ? 'id="' . $this->id . '"  ' : '';  
		$form .= $this->name ? 'name="' . $this->name . '">' : '>'; 
		return $this -> form = $form . PHP_EOL; 
 	} 
	
	 
	/*
	* Форма form input
	* <input type="text" name="name">
	* $form->input('Название','name','type','value',true) Стандартный стиль.
	*/
	function input($text = '', $name, $type = 'text', $value = '',$post = '', $size = 20,$br = true, $max = '', $names = '', $readonly = 0,$radio_id = false) { 

		$form = ''; 
		$form .= $text ?   $text  .'<br/>' : ''; 
		$form .= '<input type="' . $type . '" name="' . $name . '" id="'.$radio_id.'" value="' . $value . '" size="' . $size . '" '; 
		$form .= $readonly ? 'readonly="readonly" ' : ''; 
		$form.= $max ? 'maxlength="' . $max . '" />'.($br ? '<br />' : null).'' : '/>  '.$names.''.($br ? '<br />' : null).''; 
		$form .= $post ?  $post : '';
		return $this->form .= PHP_EOL . $form . PHP_EOL; 
	}  

	function input2($text = '', $name, $type = 'text',$value = '',$value2 = '',$names = '') {
	
		$form = ''; 
		$form .= $text ?   $text  .'<br/>' : ''; 	
		$form .= '<input  type="' . $type . '" name="' . $name . '" value="' . $value . '"' . $value2 . '/>&nbsp;'.$names.'<br/>'; 	
        
        return $this->form .= PHP_EOL . $form . PHP_EOL; 		
	}
	
	function input3($text = '', $name, $type = 'text',$value = '',$value2 = '',$names = '') {
	
		$form = ''; 
		$form .= $text ?   $text  .'' : ''; 	
		$form .= '<input  type="' . $type . '" name="' . $name . '" value="' . $value . '"' . $value2 . '/>&nbsp;'.$names.''; 	
        
        return $this->form .= PHP_EOL . $form . PHP_EOL; 		
	}	
	
	function textarea ($text = '', $name, $value = '',$post = '', $readonly = 0) { 
		$form = ''; 
		$form .= $text ? '' . $text . '<br/>' : ''; 
		$form .= '<textarea id="textarea" class="lined" name="' . $name . '"' . ($readonly ? 'readonly="readonly"' : '') . '>'; 
		$form .= $value ? $value : ''; 
		$form .= '</textarea><br/>'; 
		$form .= $post ?  $post : '';
		return $this->form .= PHP_EOL . $form . PHP_EOL; 
	} 

	function select ($text, $name, $param, $selected = 1,$optgroup = false, $optgroup2 = false) {
	
		if (!is_array($param)) { 
			$form = ''; 
		} else { 
			$form = ($text ? '' . $text . '<br/>' : null) . '<select name="' . $name . '" '.$multi.'>' . PHP_EOL;
            $form .= $optgroup;			
			$x = 1; 
			foreach ($param as $k => $v) { 
				$form .= '<option value="' . $v . '" ' . ($x==$selected ? 'selected="selected"' : '') . '>' . $k . '</option>' . PHP_EOL; 
				$x ++; 
			} 
			$form .= $optgroup2;	
			$form .= '</select><br/>'; 
		} 
		return $this->form .= $form . PHP_EOL; 
	}  
	
	public function text($text) {
	    $form = $text;
		return $this->form .= $form . PHP_EOL; 	    
	}
	public function select2($text,$name,$select,$from,$value,$option) {
	global $db;
			$form = ($text ? $text . '<br/>' : null) . '<select name="' . $name . '">' . PHP_EOL; 
            $selecting = $db->query("SELECT $select FROM `$from`");
                while($selects = $db->get_array($selecting)) {
                    $form.= '<option value="'.$selects[$value].'">'.$selects[$option].'</option>';
                }
            $form.= '</select><br/>';
		return $this->form .= $form . PHP_EOL; 
	}	
	
    //Функция для работы с input type="radio"
    //Может выводит 2 radio не больше! 	
	public function html_radio($label, $name, $values){
        $form = $label.'<br />';
            foreach($values as $key => $value){
                    $form .= '<input type="radio" name="'.$name.'" value="'.$key.'"><label for="xforward_matching_yes">'.$value.'</label>&nbsp;&nbsp;';
            }
  
		return $this->form .= $form . PHP_EOL; 
    }

	function submit ($value = 'Отправить',$name = 'submit', $br = false,$class = 'Button') { 
		$form = '<input  class="'.$class.'" type="submit" name="' . $name . '" value="' . $value . '" />' .($br ? '<br />' : null); 
				return $this->form .= $form . PHP_EOL; 

	}
	
	
	 function display() {
		echo  $this -> form .  '</form>';
    }
}



?>