53 lines
1.5 KiB
PHP
53 lines
1.5 KiB
PHP
<?php
|
|
/**
|
|
* Элемент формы
|
|
*/
|
|
namespace ctiso\Form;
|
|
|
|
class Field
|
|
{
|
|
public $hidden = false;
|
|
public $name;
|
|
public $label; // Метка поля
|
|
public $value; // Значение поля
|
|
public $type = ""; // Каждому типу элемента соответствует макрос TAL
|
|
public $error_msg = null;
|
|
public $default = null;
|
|
public $error = false;
|
|
public $require = false;
|
|
public $hint = null;
|
|
public $maxlength = null;
|
|
public $fieldset = null;
|
|
// Блоки (Убрать в отдельный класс!!!)
|
|
public $_title = array();
|
|
public $description = "";
|
|
public $alias = array();
|
|
|
|
/** @phpstan-ignore-next-line */
|
|
public function __construct ($input = [], $factory = null)
|
|
{
|
|
$this->default = null;
|
|
if (isset($input['validate'])) {
|
|
$this->require = strpos($input['validate'], 'require') !== false;
|
|
}
|
|
if (isset($input['fieldset'])) {
|
|
$this->fieldset = $input['fieldset'];
|
|
}
|
|
// Инициализация свойст обьетка
|
|
foreach (['label', 'name', 'type', 'description', 'maxlength'] as $name) {
|
|
if (isset($input[$name])) {
|
|
$this->$name = $input[$name];
|
|
}
|
|
}
|
|
}
|
|
|
|
function setValue($value/*: any*/)
|
|
{
|
|
$this->value = $value;
|
|
}
|
|
|
|
function getId()
|
|
{
|
|
return $this->name . '_label';
|
|
}
|
|
}
|