60 lines
1.4 KiB
PHP
60 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace itguild\forms\form\inputs;
|
|
|
|
use itguild\forms\form\templates\Simple\SimpleTemplate;
|
|
use itguild\forms\form\traits\CreateParams;
|
|
|
|
class Hidden extends BaseInput
|
|
{
|
|
use CreateParams;
|
|
|
|
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 = '', array $paramsArray = [])
|
|
{
|
|
$this->name = $name;
|
|
$this->value = $value;
|
|
$this->paramsArray = $paramsArray;
|
|
$this->inputTemplate = new SimpleTemplate();
|
|
}
|
|
|
|
/**
|
|
* @return $this
|
|
*/
|
|
public function create(): self
|
|
{
|
|
$paramsString = $this->createParams($this->paramsArray);
|
|
$hidden = "<input name='$this->name' type='hidden' value='$this->value' $paramsString >";
|
|
$label = "";
|
|
|
|
$this->createLabel();
|
|
|
|
$this->html = str_replace('{input}', $hidden, $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, array $paramsArray): void
|
|
{
|
|
$hidden = new self($name, $value, $paramsArray);
|
|
$hidden->create()->render();
|
|
|
|
}
|
|
} |