forms/inputs/Button.php
2024-05-28 17:10:06 +03:00

59 lines
1.5 KiB
PHP
Executable File

<?php
namespace itguild\forms\form\inputs;
use itguild\forms\form\templates\Simple\SimpleTemplate;
use itguild\forms\form\traits\CreateParams;
class Button extends BaseInput
{
use CreateParams;
private $typeInput;
private string $name;
private string $value;
private array $paramsArray;
/**
* @param string $name
* @param string $value
* @param array $paramsArray
*/
public function __construct(string $name, string $value, $typeInput, array $paramsArray = [])
{
$this->typeInput = $typeInput;
$this->name = $name;
$this->paramsArray = $paramsArray;
$this->value = $value;
$this->inputTemplate = new SimpleTemplate();
}
/**
* @return $this
*/
public function create(): self
{
$paramsString = $this->createParams($this->paramsArray);
$label = "";
$button = "<input type='$this->typeInput' value='$this->value' name='$this->name' $paramsString>";
$this->createLabel();
$this->html = str_replace('{input}', $button, $this->inputTemplate->getInputTemplate());
$this->html = str_replace('{label}', $this->labelString, $this->html);
return $this;
}
/**
* @param string $name
* @param string $value
* @param array $paramsArray
* @return void
*/
public static function build( string $name, string $value, string $typeInput, array $paramsArray = []): void
{
$button = new self($name, $value, $typeInput, $paramsArray);
$button->create()->render();
}
}