ILIAS  release_8 Revision v8.24
class.ilEMailInputGUI.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
26{
27 protected string $value = "";
28 protected int $size = 30;
29 protected int $max_length = 80;
30 protected bool $allowRFC822 = false;
31 protected bool $retype = false;
32 protected string $retypevalue = '';
33
34 public function __construct(
35 string $a_title = "",
36 string $a_postvar = ""
37 ) {
38 global $DIC;
39
40 $this->lng = $DIC->language();
41 parent::__construct($a_title, $a_postvar);
42 $this->setRetype(false);
43 }
44
45 public function setValue(string $a_value): void
46 {
47 $this->value = $a_value;
48 }
49
50 public function getValue(): string
51 {
52 return $this->value;
53 }
54
55 public function setValueByArray(array $a_values): void
56 {
57 $this->setValue($a_values[$this->getPostVar()] ?? "");
58 $this->setRetypeValue($a_values[$this->getPostVar() . '_retype'] ?? "");
59 }
60
66 public function allowRFC822(bool $a_value): void
67 {
68 $this->allowRFC822 = $a_value;
69 }
70
71 // get string parameter kindly
72 protected function sanitize($key): string
73 {
74 $t = $this->refinery->kindlyTo()->string();
76 (string) ($this->getRequestParam($key, $t) ?? ""),
77 !$this->allowRFC822
78 );
79 }
80
81 public function checkInput(): bool
82 {
84
85 if ($this->getRequired() && trim($this->str($this->getPostVar())) == "") {
86 $this->setAlert($lng->txt("msg_input_is_required"));
87 return false;
88 }
89 if ($this->getRetype() &&
90 ($this->sanitize($this->getPostVar()) != $this->sanitize($this->getPostVar() . '_retype'))) {
91 $this->setAlert($lng->txt('email_not_match'));
92 return false;
93 }
94 if (!ilUtil::is_email($this->sanitize($this->getPostVar())) &&
95 trim($this->sanitize($this->getPostVar())) != ""
96 ) {
97 $this->setAlert($lng->txt("email_not_valid"));
98 return false;
99 }
100 return true;
101 }
102
103 public function getInput(): string
104 {
105 return trim($this->sanitize($this->getPostVar()));
106 }
107
108 public function insert(ilTemplate $a_tpl): void
109 {
111
112 $ptpl = new ilTemplate('tpl.prop_email.html', true, true, 'Services/Form');
113
114 if ($this->getRetype()) {
115 $ptpl->setCurrentBlock('retype_email');
116 $ptpl->setVariable('RSIZE', $this->getSize());
117 $ptpl->setVariable('RID', $this->getFieldId());
118 $ptpl->setVariable('RMAXLENGTH', $this->getMaxLength());
119 $ptpl->setVariable('RPOST_VAR', $this->getPostVar());
120
121 $retype_value = $this->getRetypeValue();
122 $ptpl->setVariable('PROPERTY_RETYPE_VALUE', ilLegacyFormElementsUtil::prepareFormOutput($retype_value));
123 if ($this->getDisabled()) {
124 $ptpl->setVariable('RDISABLED', ' disabled="disabled"');
125 }
126 $ptpl->setVariable('TXT_RETYPE', $lng->txt('form_retype_email'));
127 $ptpl->parseCurrentBlock();
128 }
129
130 $ptpl->setVariable('POST_VAR', $this->getPostVar());
131 $ptpl->setVariable('ID', $this->getFieldId());
132 $ptpl->setVariable('PROPERTY_VALUE', ilLegacyFormElementsUtil::prepareFormOutput($this->getValue()));
133 $ptpl->setVariable('SIZE', $this->getSize());
134 $ptpl->setVariable('MAXLENGTH', $this->getMaxLength());
135 if ($this->getDisabled()) {
136 $ptpl->setVariable('DISABLED', ' disabled="disabled"');
137 $ptpl->setVariable('HIDDEN_INPUT', $this->getHiddenTag($this->getPostVar(), $this->getValue()));
138 }
139
140 if ($this->getRequired()) {
141 $ptpl->setVariable("REQUIRED", "required=\"required\"");
142 }
143
144 $a_tpl->setCurrentBlock('prop_generic');
145 $a_tpl->setVariable('PROP_GENERIC', $ptpl->get());
146 $a_tpl->parseCurrentBlock();
147 }
148
149 public function setRetype(bool $a_val): void
150 {
151 $this->retype = $a_val;
152 }
153
154 public function getRetype(): bool
155 {
156 return $this->retype;
157 }
158
159 public function setRetypeValue(string $a_retypevalue): void
160 {
161 $this->retypevalue = $a_retypevalue;
162 }
163
164 public function getRetypeValue(): string
165 {
166 return $this->retypevalue;
167 }
168
169 public function setSize(int $size): void
170 {
171 $this->size = $size;
172 }
173
174 public function getSize(): int
175 {
176 return $this->size;
177 }
178
179 public function setMaxLength(int $max_length): void
180 {
181 $this->max_length = $max_length;
182 }
183
184 public function getMaxLength(): int
185 {
186 return $this->max_length;
187 }
188}
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:514
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setValueByArray(array $a_values)
setRetypeValue(string $a_retypevalue)
__construct(string $a_title="", string $a_postvar="")
allowRFC822(bool $a_value)
Allow extended email address format.
setMaxLength(int $max_length)
insert(ilTemplate $a_tpl)
checkInput()
Check input, strip slashes etc.
setValue(string $a_value)
This class represents a property in a property form.
getHiddenTag(string $a_post_var, string $a_value)
getRequestParam(string $key, Refinery\Transformation $t)
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
static prepareFormOutput($a_str, bool $a_strip=false)
special template class to simplify handling of ITX/PEAR
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
static is_email(string $a_email, ilMailRfc822AddressParserFactory $mailAddressParserFactory=null)
This preg-based function checks whether an e-mail address is formally valid.
global $DIC
Definition: feed.php:28
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
string $key
Consumer key/client ID value.
Definition: System.php:193