diff --git a/composer.json b/composer.json index 7fbcfde..728025e 100644 --- a/composer.json +++ b/composer.json @@ -8,7 +8,6 @@ } ], "require": { - //PHP7.1 "krutush/template": "dev-master" }, "autoload": { diff --git a/src/Element.php b/src/Element.php index b156e6e..c946c26 100644 --- a/src/Element.php +++ b/src/Element.php @@ -9,14 +9,19 @@ class Element{ $this->data['name'] = $name; } + public function rename(string $name): self{ + $this->data['name'] = $name; + return $this; + } + public function name() : string{ return $this->data['name']; } - public function required(bool $value = true) : Element{ + public function required(bool $value = true) : self{ $this->data['required'] = $value; return $this; } - public function value(string $value) : Element{ + public function value(string $value) : self{ $this->data['value'] = $value; return $this; } @@ -25,7 +30,7 @@ class Element{ return $this->data['value']; } - public function error(bool $value = true) : Element{ + public function error(bool $value = true) : self{ $this->data['error'] = $value; return $this; } diff --git a/src/Form.php b/src/Form.php index 0aa6a87..4f87808 100644 --- a/src/Form.php +++ b/src/Form.php @@ -58,7 +58,29 @@ class Form { $this->method = $method; $this->url = $url; } - return '
'; + $html = ''; + $html .= " + +"; + return $html; } public function end(string $more = '') : string{ @@ -80,7 +102,10 @@ class Form { return ''; } - function input(string $name) : Element{ + function input(string $name, bool $add = true) : Element{ + if($add == false) + return new Input($name); + if($this->set == true){ $input = $this->get($name); if(isset($input)) @@ -91,7 +116,9 @@ class Form { return $input; } - function select(string $name) : Element{ + function select(string $name, bool $add = true) : Element{ + if($add == false) + return new Select($name); if($this->set == true){ $input = $this->get($name); if(isset($input)) @@ -113,7 +140,7 @@ class Form { return $input; } - public function add(Element $thing) : void{ + public function add(Element $thing){ if($this->set == false) $this->elements[] = $thing; } diff --git a/src/Input.php b/src/Input.php index 7aee67d..f65c6c8 100644 --- a/src/Input.php +++ b/src/Input.php @@ -21,6 +21,13 @@ class Input extends Element{ return $this; } + public function checkbox(): Input{ + $this->data['type'] = 'checkbox'; + $this->data['checkbox'] = true; + $this->data['value'] = $this->data['name']; + return $this; + } + public function minlength(int $value) : Input{ $this->data['minlength'] = $value; return $this; @@ -96,7 +103,6 @@ class Input extends Element{ (isset($this->data['type']) ? 'type="'.$this->data['type'].'" ' : ''). (isset($this->data['title']) ? 'title="'.$this->data['title'].'" ' : ''). (isset($this->data['pattern']) ? 'pattern="'.$this->data['pattern'].'" ' : ''). - (isset($this->data['pattern']) ? 'pattern="'.$this->data['pattern'].'" ' : ''). (isset($this->data['minlength']) ? 'minlength="'.$this->data['minlength'].'" ' : ''). (isset($this->data['maxlength']) ? 'maxlength="'.$this->data['maxlength'].'" ' : ''). (isset($this->data['required']) && $this->data['required'] == true ? 'required ' : ''). diff --git a/src/Select.php b/src/Select.php index d64e3d2..5d8ba84 100644 --- a/src/Select.php +++ b/src/Select.php @@ -24,6 +24,15 @@ class Select extends Element{ return $this; } + public function other(Input $input, string $text, string $more = ''): Select{ + $input->rename($this->name()); + $this->data['other'] = $input; + $this->data['other.text'] = $text; + $this->data['other.more'] = $more; + return $this; + } + + public function valid(mixed $data)/*: bool|string*/{ $parent = parent::valid($data); if($parent !== true || !isset($data)) @@ -33,16 +42,50 @@ class Select extends Element{ if($option['value'] == $data) return $parent; } + if(isset($this->data['other'])){ + $input = $this->data['other']; + return $input->valid($data); + } + return 'incorrect'; } - public function html(string $more = '') : string{ - $html = ''; + + $html = ''; + if(isset($this->data['other'])){ + $html .= $this->data['other']->html($inputmore.$this->data['other.more']); + } + return $html; } } \ No newline at end of file