Whistik

Untitled

May 23rd, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.49 KB | None | 0 0
  1. <?php
  2.  
  3. class FormManager{
  4.  
  5.     private $FormElementStructure = [
  6.         "action",
  7.         "method",
  8.         "class"];
  9.     private $InputElementStructure = [
  10.         "type",
  11.         "name",
  12.         "placeholder",
  13.         "value",
  14.         "class",
  15.         "id"];
  16.     private $SelectElementStructure = [
  17.         "name",
  18.         "class",
  19.         "id"];
  20.     private $SelectOptionStructure = [
  21.         "value",
  22.         "class",
  23.         "id"];
  24.  
  25.     public function CreateForm( $Form )
  26.     {
  27.         for($i=0;$i<count($Form);$i++){
  28.             $FormElement[] = $this->FormElementStructure[$i] . "='" . $Form[$i]."' ";
  29.         }
  30.         $FormHeader = "<form ".join(" ", $FormElement)." >";
  31.         print( $FormHeader );
  32.     }
  33.     public function CreateSelect( $Select )
  34.     {
  35.         for($i=0;$i<count($Select);$i++){
  36.             $SelectElement[] = $this->SelectElementStructure[$i] . "='" .$Select[$i]. "' ";
  37.         }  
  38.  
  39.         print( $electHeader = "<select ".join(" ", $SelectElement)." >" );
  40.     }
  41.  
  42.     public function AddOption( $SelectOption, $SelectOptionText, $SelectOptionSelected = false, $SelectOptionDisabled = false )
  43.     {
  44.         for($i=0;$i<count($SelectOption);$i++){
  45.             $SelectOptionElement[] = $this->SelectOptionStructure[$i] . "='" .$SelectOption[$i]. "' ";
  46.         }
  47.         $SelectOptionHeader = "<option ".join(" ", $SelectOptionElement);
  48.         $SelectOptionFooter = "</option>";
  49.        
  50.         if($SelectOptionSelected != true && $SelectOptionDisabled != true){
  51.             print( $SelectOptionHeader." >".$SelectOptionText.$SelectOptionFooter );
  52.         }elseif($SelectOptionSelected != false && $SelectOptionDisabled != true){
  53.             print( $SelectOptionHeader." selected >".$SelectOptionText.$SelectOptionFooter );
  54.         }elseif($SelectOptionSelected != true && $SelectOptionDisabled != false){
  55.             print( $SelectOptionHeader." disabled >".$SelectOptionText.$SelectOptionFooter );
  56.         }
  57.         $SelectOptionElement = null;
  58.     }
  59.    
  60.     public function AddInput( $Input, $InputRequired = false, $InputDisabled = false )
  61.     {
  62.         for($i=0;$i<count($Input);$i++){
  63.             $InputElement[$i] = $this->InputElementStructure[$i] . "='" . $Input[$i]."' ";
  64.         }
  65.         $InputHeader = "<input ".join(" ", $InputElement);
  66.         $InputFooter = ">";
  67.         if($InputRequired != true && $InputDisabled != true){
  68.             print( $InputHeader.$InputFooter );
  69.         }elseif($InputRequired != false && $InputDisabled != true){
  70.             print( $InputHeader." required ".$InputFooter );
  71.         }elseif($InputRequired != true && $InputDisabled != false){
  72.             print( $InputHeader." disabled ".$InputFooter );
  73.         }
  74.         $InputElement = null;
  75.     }
  76.  
  77.     public function FinishForm( )
  78.     {
  79.         print( "</form>" );
  80.     }
  81.  
  82.     public function FinishSelect( )
  83.     {
  84.         print( "</select>" );
  85.     }
  86.    
  87. }
Add Comment
Please, Sign In to add comment