Advertisement
Whistik

Untitled

May 20th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.24 KB | None | 0 0
  1. <?php
  2.  
  3. class FormManager{
  4.  
  5.     private $SERVER_REQUEST;
  6.     private $DB;
  7.     private $FormFooter;
  8.     private $FormHeader;
  9.     private $FormElement;
  10.     private $FormElementStructure = [
  11.         "action",
  12.         "method",
  13.         "class"];
  14.     private $InputElement = [];
  15.     private $Inputs = [];
  16.     private $InputElementStructure = [
  17.         "type",
  18.         "name",
  19.         "placeholder",
  20.         "value",
  21.         "class",
  22.         "id"];
  23.     private $InputBody = [];
  24.     private $InputCounts;
  25.     private $InputElementTemp = [];
  26.     private $InputFooter;
  27.     private $InputHeader;
  28.  
  29.     public function __construct( )
  30.     {
  31.         $this->SERVER_REQUEST = (object) Application::GetApplication()->SERVER_REQUEST;
  32.         $this->DB = Application::GetApplication()->DB;
  33.     }
  34.  
  35.     public function CreateForm( $Form )
  36.     {
  37.         $Form = $Form;
  38.         for($i=0;$i<count($Form);$i++){
  39.             $this->FormElementTemp[] = $this->FormElementStructure[$i] . "='" . $Form[$i]."' ";
  40.         }
  41.         $this->FormHeader = "<form ".join(" ", $this->FormElementTemp)." >";
  42.         $this->FormFooter = "</form>";
  43.         print( $this->FormHeader );
  44.     }
  45.     public function AddInput( $Input, $InputRequired = false, $InputDisabled = false )
  46.     {
  47.         for($i=0;$i<count($Input);$i++){
  48.             $this->InputElement[] = $Input[$i];
  49.         }
  50.         for($i=0;$i<count($this->InputElement);$i++){
  51.             $this->InputElementTemp[$i] = $this->InputElementStructure[$i] . "='" . $this->InputElement[$i]."' ";
  52.         }
  53.         $this->InputHeader = "<input ";
  54.         $this->InputFooter = "/>";
  55.         for($i=0;$i<count($this->InputElementTemp);$i++){
  56.             $this->InputBody[$i] = $this->InputElementTemp[$i];
  57.         }
  58.         $this->InputCounts = $this->InputCounts + 1;
  59.  
  60.         $this->InputElementTemp = null;
  61.         $this->InputElement = null;
  62.         if($InputRequired == false && $InputDisabled == false){
  63.             $this->Inputs[] = $this->InputHeader.join(" ", $this->InputBody).$this->InputFooter;
  64.         }elseif($InputDisabled == true){
  65.             $this->Inputs[] = $this->InputHeader.join(" ", $this->InputBody)." disabled ".$this->InputFooter;
  66.         }elseif($InputRequired == true){
  67.             $this->Inputs[] = $this->InputHeader.join(" ", $this->InputBody)." required ".$this->InputFooter;
  68.         }
  69.         print( $this->RenderInput($this->InputCounts) );
  70.     }
  71.     private function RenderInput( $InputID )
  72.     {
  73.         return $this->Inputs[$InputID - 1];
  74.     }
  75.     public function FinishForm( )
  76.     {
  77.         print( "</form>" );
  78.     }
  79.    
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement