Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class FormManager{
- private $SERVER_REQUEST;
- private $DB;
- private $FormFooter;
- private $FormHeader;
- private $FormElement;
- private $FormElementStructure = [
- "action",
- "method",
- "class"];
- private $InputElement = [];
- private $Inputs = [];
- private $InputElementStructure = [
- "type",
- "name",
- "placeholder",
- "value",
- "class",
- "id"];
- private $InputBody = [];
- private $InputCounts;
- private $InputElementTemp = [];
- private $InputFooter;
- private $InputHeader;
- public function __construct( )
- {
- $this->SERVER_REQUEST = (object) Application::GetApplication()->SERVER_REQUEST;
- $this->DB = Application::GetApplication()->DB;
- }
- public function CreateForm( $Form )
- {
- $Form = $Form;
- for($i=0;$i<count($Form);$i++){
- $this->FormElementTemp[] = $this->FormElementStructure[$i] . "='" . $Form[$i]."' ";
- }
- $this->FormHeader = "<form ".join(" ", $this->FormElementTemp)." >";
- $this->FormFooter = "</form>";
- print( $this->FormHeader );
- }
- public function AddInput( $Input, $InputRequired = false, $InputDisabled = false )
- {
- for($i=0;$i<count($Input);$i++){
- $this->InputElement[] = $Input[$i];
- }
- for($i=0;$i<count($this->InputElement);$i++){
- $this->InputElementTemp[$i] = $this->InputElementStructure[$i] . "='" . $this->InputElement[$i]."' ";
- }
- $this->InputHeader = "<input ";
- $this->InputFooter = "/>";
- for($i=0;$i<count($this->InputElementTemp);$i++){
- $this->InputBody[$i] = $this->InputElementTemp[$i];
- }
- $this->InputCounts = $this->InputCounts + 1;
- $this->InputElementTemp = null;
- $this->InputElement = null;
- if($InputRequired == false && $InputDisabled == false){
- $this->Inputs[] = $this->InputHeader.join(" ", $this->InputBody).$this->InputFooter;
- }elseif($InputDisabled == true){
- $this->Inputs[] = $this->InputHeader.join(" ", $this->InputBody)." disabled ".$this->InputFooter;
- }elseif($InputRequired == true){
- $this->Inputs[] = $this->InputHeader.join(" ", $this->InputBody)." required ".$this->InputFooter;
- }
- print( $this->RenderInput($this->InputCounts) );
- }
- private function RenderInput( $InputID )
- {
- return $this->Inputs[$InputID - 1];
- }
- public function FinishForm( )
- {
- print( "</form>" );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement