first commit
This commit is contained in:
58
inputs/TextInput.php
Executable file
58
inputs/TextInput.php
Executable file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace itguild\forms\form\inputs;
|
||||
|
||||
use itguild\forms\form\templates\Simple\SimpleTemplate;
|
||||
use itguild\forms\form\traits\CreateParams;
|
||||
|
||||
class TextInput extends BaseInput
|
||||
{
|
||||
|
||||
use CreateParams;
|
||||
private string $name;
|
||||
private array $paramsArray;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param array $paramsArray
|
||||
*/
|
||||
public function __construct(string $name, array $paramsArray = [])
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->paramsArray = $paramsArray;
|
||||
$this->inputTemplate = new SimpleTemplate();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return self
|
||||
*/
|
||||
public function create(): self
|
||||
{
|
||||
$paramsString = $this->createParams($this->paramsArray);
|
||||
$label = "";
|
||||
$input = "<input name='$this->name' $paramsString >";
|
||||
|
||||
$this->createLabel();
|
||||
|
||||
$this->html = str_replace('{input}', $input, $this->inputTemplate->getInputTemplate());
|
||||
$this->html = str_replace('{label}', $this->labelString, $this->html);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param array $paramsArray
|
||||
* @return void
|
||||
*/
|
||||
public static function build(string $name, array $paramsArray = []): void
|
||||
{
|
||||
$input = new self($name, $paramsArray);
|
||||
$input->create()->render();
|
||||
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user