depage-forms v1.4.1
html forms made easy
Loading...
Searching...
No Matches
Elements/Url.php
Go to the documentation of this file.
1<?php
2
10
11namespace Depage\HtmlForm\Elements;
12
37class Url extends Text
38{
48 protected function setDefaults(): void
49 {
50 parent::setDefaults();
51
52 $this->defaults['errorMessage'] = _('Please enter a valid URL');
53
54 // @todo add option to test url by domain name (dns) or also with a request (for http/https urls)
55 }
56
62 protected function typeCastValue(): void
63 {
64 parent::typeCastValue();
65
66 if ($this->normalize) {
67 $this->value = \Depage\HtmlForm\Validators\Url::normalizeUrl($this->value);
68 }
69 }
70
76 protected function htmlValue(): string
77 {
78 $value = $this->value === null ? $this->defaultValue : $this->value;
80
81 return $this->htmlEscape($value);
82 }
83}
84
85/* vim:set ft=php sw=4 sts=4 fdm=marker et : */
htmlEscape(array|string $options=[])
Escapes HTML in strings and arrays of strings.
Definition Element.php:261
$value
Input elements's value.
Definition Input.php:124
HTML text input type.
Definition Text.php:40
typeCastValue()
Converts value into htmlDOM.
htmlValue()
Returns the value of the element as HTML.
setDefaults()
collects initial values across subclasses
static normalizeUrl($url)
normalizes url
static humanReadableUrl($url)
changes encoded url to a human readable format