Validators for Form Fields

This commit is contained in:
2024-07-05 13:39:02 +02:00
parent 7043d56329
commit 6bb19ad6b0
9 changed files with 262 additions and 2 deletions
-58
View File
@@ -1,58 +0,0 @@
<?php
class Hyperlink
{
/*
* Private members
*/
private string $uri;
private string $title;
private ?string $colour;
/*
* Constructor
*/
public function __construct(string $uri, string $title, string $colour = null)
{
$this->uri = $uri;
$this->title = $title;
$this->setColour($colour);
}
/*
* Getters and Setters
*/
public function setColour(string $colour = null)
{
if ($colour === null) {
$this->colour = null;
return;
}
if (!preg_match("/^#([0-9A-Fa-f]{3,4}|[0-9A-Fa-f]{6}|[0-9A-Fa-f]{8})$/", $colour)) {
trigger_error("Colour invalid", E_USER_WARNING);
return;
}
$this->colour = $colour;
}
public function getColour()
{
return $this->colour ?? "No colour specified";
}
/*
* Meta
*/
public function __toString()
{
$style = $this->colour ? "style=\"color:$this->colour;\"" : "";
return <<<END
<a href="$this->uri" $style>$this->title</a>
END;
}
}
+1 -1
View File
@@ -14,7 +14,7 @@
Headers::html();
//Testdatei für die Klasse Hyperlink
include_once "./hyperlink.php";
include_once "../classes/hyperlink/hyperlink.php";
//Objektinstanzen
$link1 = new Hyperlink("https://www.google.de", "Google");