11namespace Depage\HtmlForm\Abstracts;
13use Depage\HtmlForm\Validators;
268 $this->type = str_replace(
'Depage\\HtmlForm\\Elements\\',
'', get_class($this));
269 $this->formName = $form->getName();
271 parent::__construct(
$name, $parameters, $form);
273 $this->validator = (isset($parameters[
'validator']))
289 parent::setDefaults();
291 $this->defaults[
'autocapitalize'] =
null;
292 $this->defaults[
'autocomplete'] =
null;
293 $this->defaults[
'autocorrect'] =
null;
294 $this->defaults[
'autofocus'] =
false;
295 $this->defaults[
'errorMessage'] = _(
'Please enter valid data');
297 $this->defaults[
'labelHtml'] =
'';
298 $this->defaults[
'marker'] =
'*';
299 $this->defaults[
'required'] =
false;
300 $this->defaults[
'readonly'] =
false;
301 $this->defaults[
'title'] =
false;
302 $this->defaults[
'class'] =
'';
303 $this->defaults[
'lang'] =
'';
304 $this->defaults[
'helpMessage'] =
'';
305 $this->defaults[
'helpMessageHtml'] =
'';
306 $this->defaults[
'dataPath'] =
null;
319 if (!$this->validated) {
320 $this->validated =
true;
323 ($this->value !==
null)
342 $this->validated =
true;
343 $this->valid =
false;
357 return $this->validator->validate($this->value);
372 && $this->value !==
'0'
373 && $this->value !==
false
390 $this->value = $newValue;
392 $this->validated =
false;
434 $this->errorMessage = $message;
472 $this->defaultValue = $newDefaultValue;
522 $this->validated =
false;
536 if ($this->required) {
539 if ($this->disabled) {
542 if ($this->readonly) {
545 if (($this->value !==
null) && (!$this->
validate())) {
548 if (isset($this->skin)) {
551 if (!empty($this->
class)) {
568 return ($this->required) ?
" <em>" . $this->
htmlEscape($this->marker) .
"</em>" :
"";
580 if ($this->required) {
581 $attributes .=
' required="required"';
583 if ($this->disabled) {
584 $attributes .=
' disabled="disabled"';
586 if ($this->readonly) {
587 $attributes .=
' readonly="readonly"';
589 if ($this->autofocus) {
590 $attributes .=
' autofocus="autofocus"';
597 foreach ($autoAttributes as $attr) {
598 if (!is_null($this->$attr)) {
600 $attributes .=
" $attr=\"on\"";
602 $attributes .=
" $attr=\"off\"";
608 if (!is_null($this->autocomplete)) {
609 if (is_string($this->autocomplete)) {
610 $attributes .=
" autocomplete=\"" . $this->
htmlEscape($this->autocomplete) .
"\"";
611 } elseif ($this->autocomplete ===
true) {
612 $attributes .=
" autocomplete=\"on\"";
614 $attributes .=
" autocomplete=\"off\"";
628 return parent::htmlDataAttributes();
638 $attributes =
"id=\"{$this->formName}-{$this->name}\" ";
640 $attributes .=
"class=\"" . $this->
htmlClasses() .
"\"";
658 return $this->
htmlEscape($this->value ===
null ? $this->defaultValue : $this->value);
669 && $this->value !==
null
670 && $this->errorMessage !==
""
688 if (isset($this->helpMessage) && !empty($this->helpMessage)) {
692 if (isset($this->helpMessageHtml) && !empty($this->helpMessageHtml)) {
694 $helpMessage =
"<span class=\"helpMessage\">" . $this->helpMessageHtml .
"</span>";
$valid
Contains element validation status/result.
log(string $argument, string $type=null)
error & warning logger
htmlEscape(array|string $options=[])
Escapes HTML in strings and arrays of strings.
htmlInputAttributes()
Returns string of HTML attributes for input element.
$dataPath
Extra information about the data that is saved inside the element.
$value
Input elements's value.
$formName
Name of the parent HTML form.
getLabel()
Returns the current input elements' label.
$label
Input element - HTML label.
validate()
Validates input element.
$autofocus
HTML autofocus attribute.
setValue(mixed $newValue)
set the input element value
$class
class for paragraph
$errorMessage
Message that gets displayed in case of invalid input.
$helpMessageHtml
Extra help message in html format.
htmlHelpMessage()
Returns HTML-rendered helpMessage.
$required
True if the input element is required to hold a value to be valid.
getErrorMessage()
getErrorMessage
clearValue()
resets the value to null
$classes
HTML classes attribute for rendering the input element.
$autocomplete
HTML autocomplete attribute.
typeCastValue()
converts element value
htmlDataAttributes()
Returns dataAttr escaped as attribute string.
htmlWrapperAttributes()
Returns string of HTML attributes for element wrapper paragraph.
__construct(string $name, array $parameters, object $form)
input class constructor
$lang
Input element - lang.
$autocapitalize
HTML autocapitalize attribute.
htmlMarker()
Returns elements' required-indicator.
validatorCall()
custom validator call hook
$type
Input element type - HTML input type attribute.
$defaultValue
Input element - default value.
setErrorMessage(string $message)
setErrorMessage
$readonly
wether a input element will be readonly
$validator
Holds validator object reference.
$helpMessage
Extra help message.
htmlValue()
Returns HTML-rendered element value.
$marker
Input element - HTML marker text that marks required fields.
$autocorrect
HTML autocorrect attribute.
setAutofocus(bool $autofocus=true)
Sets the HTML autofocus-attribute of the current input element.
getValue()
Returns the current input elements' value.
htmlClasses()
Returns string of the elements' HTML-classes, separated by spaces.
setDefaults()
Sets the default values for input elements.
setDefaultValue(mixed $newDefaultValue)
set the initial input element value
invalidate()
Invalidates input.
$title
Input element - HTML title.
setLabel(string $label)
set the label of the input
setRequired(bool $required=true)
Sets the HTML required-attribute of the current input element.
isEmpty()
says wether the element value is empty
$labelHtml
Input element - HTML label in html format.
$pattern
HTML pattern attribute.
getDefaultValue()
gets the initial input element value
htmlErrorMessage()
Returns HTML-rendered error message.
static factory($argument, $log=null)
valdiator object factory
Validators for HTML input-elements.