diff --git a/index.php b/index.php index bc36fa4..d248bfe 100644 --- a/index.php +++ b/index.php @@ -3,6 +3,8 @@ use itguild\forms\Form; use \itguild\forms\inputs\TextInput; use \itguild\forms\inputs\Radio; +use \itguild\forms\inputs\Select; +use \itguild\forms\ActiveForm; ini_set("display_errors", true); error_reporting(-1); @@ -27,22 +29,22 @@ $form->select("select", ["class1" => "option", "class2" => "b2", "class3" => "b4 $form->button('button', "Кнопка", ["id" => "button"]); $form->endForm(); -$activeForm = new \itguild\forms\ActiveForm(); +$activeForm = new ActiveForm(); $activeForm->field(class: TextInput::class, name: 'nnn', params: ["style" => "color:RED;display:flex"]) - ->setLabel("dfdfdffd") ->render(); $activeForm->field(class: TextInput::class, name: 'bbb', params: []) + ->render(); + +$activeForm->field(class: Radio::class, name: 'nameee',params: ["style" => "color:RED;display:flex"]) + ->setOptions(['1' => 'bbb1', '2' => 'vvv3', 3 => 'ggg3', 4 => 'fgfgfgfg4']) + ->setLabel("bbb222bbb") + ->render(); + +$activeForm->field(class: Radio::class, name: 'nameee',params: ["style" => "color:RED;display:flex"]) ->setLabel("bbbbbb") ->render(); -$activeForm->field(class: Radio::class, name: 'nameee',params: ["style" => "color:RED;display:flex"]) - ->setOptions(['1' => 'bbb1', '2' => 'vvv3', 3 => 'ggg3', 4 => 'fgfgfgfg4']) - ->render(); - -$activeForm->field(class: Radio::class, name: 'nameee',params: ["style" => "color:RED;display:flex"]) - ->render(); - -$activeForm->field(\itguild\forms\inputs\Select::class, 'ddd', ['value' => 2]) +$activeForm->field(Select::class, 'ddd', ['value' => 2]) ->setOptions(['1' => 'bbb1', '2' => 'vvv3', 3 => 'ggg3', 4 => 'fgfgfgfg4']) ->render(); \ No newline at end of file diff --git a/src/inputs/Button.php b/src/inputs/Button.php index 7b29f25..34021b1 100644 --- a/src/inputs/Button.php +++ b/src/inputs/Button.php @@ -12,7 +12,8 @@ class Button extends BaseInput private string $name; private string $value; private array $paramsArray; - + private bool $hasLabel = false; + private string $labelTitle = ''; /** * @param string $name @@ -33,6 +34,9 @@ class Button extends BaseInput { $paramsString = $this->createParams($this->paramsArray); $this->html = ""; + if($this->hasLabel == true) { + $this->html = " $this->html"; + } return $this; } @@ -54,7 +58,9 @@ class Button extends BaseInput */ public function setLabel(string $title): self { - $this->html = ""; + $this->hasLabel = true; + $this->labelTitle = $title; + return $this; } diff --git a/src/inputs/Checkbox.php b/src/inputs/Checkbox.php index d00ce18..1ed6aeb 100644 --- a/src/inputs/Checkbox.php +++ b/src/inputs/Checkbox.php @@ -12,6 +12,8 @@ class Checkbox extends BaseInput private string $name; private string $value; private array $paramsArray; + private bool $hasLabel = false; + private string $labelTitle = ''; /** @@ -33,6 +35,10 @@ class Checkbox extends BaseInput { $paramsString = $this->createParams($this->paramsArray); $this->html = ""; + if($this->hasLabel == true) { + $this->html = " $this->html"; + } + return $this; } @@ -55,7 +61,9 @@ class Checkbox extends BaseInput */ public function setLabel(string $title): self { - $this->html = ""; + $this->hasLabel = true; + $this->labelTitle = $title; + return $this; } } \ No newline at end of file diff --git a/src/inputs/Label.php b/src/inputs/Label.php index 35f74f7..5b197fc 100644 --- a/src/inputs/Label.php +++ b/src/inputs/Label.php @@ -31,6 +31,7 @@ class Label extends BaseInput $paramsString = $this->createParams($this->paramsArray); $this->html = ""; + return $this; } diff --git a/src/inputs/Radio.php b/src/inputs/Radio.php index 0d8cfe9..5925737 100644 --- a/src/inputs/Radio.php +++ b/src/inputs/Radio.php @@ -28,8 +28,10 @@ class Radio extends BaseInput { $paramsString = $this->createParams($this->paramsArray); $optionsString = $this->createOption($this->options, $this->value); - $this->html = "$optionsString"; - $this->html = " $this->html"; + $this->html = "$optionsString"; + if($this->hasLabel == true) { + $this->html = " $this->html"; + } return $this; } diff --git a/src/inputs/Select.php b/src/inputs/Select.php index 9fb67c8..1e4bbf7 100644 --- a/src/inputs/Select.php +++ b/src/inputs/Select.php @@ -42,7 +42,9 @@ class Select extends BaseInput $paramsString = $this->createParams($this->paramsArray); $optionsString = $this->createOption($this->options, $this->value); $this->html = ""; - $this->html = " $this->html"; + if($this->hasLabel == true) { + $this->html = " $this->html"; + } return $this; diff --git a/src/inputs/TextArea.php b/src/inputs/TextArea.php index 2e9140e..74b4cd7 100644 --- a/src/inputs/TextArea.php +++ b/src/inputs/TextArea.php @@ -12,6 +12,8 @@ class TextArea extends BaseInput private $name; private $value; private $paramsArray; + private bool $hasLabel = false; + private string $labelTitle = ''; /** * @param string $name @@ -32,6 +34,9 @@ class TextArea extends BaseInput { $paramsString = $this->createParams($this->paramsArray); $this->html = ""; + if($this->hasLabel == true) { + $this->html = " $this->html"; + } return $this; } @@ -55,7 +60,9 @@ class TextArea extends BaseInput */ public function setLabel(string $title): self { - $this->html = ""; + $this->hasLabel = true; + $this->labelTitle = $title; + return $this; } diff --git a/src/inputs/TextInput.php b/src/inputs/TextInput.php index 185cd46..7e51e5e 100644 --- a/src/inputs/TextInput.php +++ b/src/inputs/TextInput.php @@ -11,6 +11,8 @@ class TextInput extends BaseInput use CreateParams; private string $name; + private bool $hasLabel = false; + private string $labelTitle = ''; private array $paramsArray; @@ -31,6 +33,9 @@ class TextInput extends BaseInput { $paramsString = $this->createParams($this->paramsArray); $this->html = ""; + if($this->hasLabel == true) { + $this->html = " $this->html"; + } return $this; } @@ -53,7 +58,9 @@ class TextInput extends BaseInput */ public function setLabel(string $title): self { - $this->html = ""; + $this->hasLabel = true; + $this->labelTitle = $title; + return $this; }