28 protected $autocomplete = NULL;
29 protected $trim = FALSE;
30 protected $inputType =
'text';
31 protected $html5pattern = NULL;
44 function __construct ($label, $description, $ldapName, $required = FALSE, $defaultValue =
"", $acl =
"", $regexp =
"", $example = NULL)
46 parent::__construct($label, $description, $ldapName, $required, $defaultValue, $acl);
47 $this->setPattern($regexp);
48 $this->example = ($example === NULL ? $defaultValue : $example);
51 function setExample ($example)
53 $this->example = $example;
56 public function getExample ()
58 return $this->example;
61 function setPattern ($pattern)
63 $this->pattern = $pattern;
64 if (preg_match(
'/^(.)\^(.*)\$\1$/', $pattern, $m)) {
68 $this->html5pattern = $m[2];
70 $this->html5pattern = NULL;
74 function renderFormInput ():
string 76 $id = $this->getHtmlId();
78 'value' => $this->getValue()
80 if (!empty($this->managedAttributes)) {
81 $js = $this->managedAttributesJS();
82 $attributes[
'onChange'] =
'javascript:'.$js;
84 if ($this->autocomplete !== NULL) {
85 $attributes[
'autocomplete'] = $this->autocomplete;
87 if ($this->html5pattern !== NULL) {
88 $attributes[
'pattern'] = $this->html5pattern;
90 if ($this->isSubAttribute) {
91 $attributes[
'class'] =
'subattribute';
92 } elseif ($this->isRequired()) {
93 $attributes[
'required'] =
'required';
95 $display = $this->renderInputField($this->inputType, $id, $attributes);
99 function renderTemplateInput ():
string 101 $id = $this->getHtmlId();
103 'value' => $this->getValue()
105 if ($this->autocomplete !== NULL) {
106 $attributes[
'autocomplete'] = $this->autocomplete;
108 if ($this->isSubAttribute) {
109 $attributes[
'class'] =
'subattribute';
111 $display = $this->renderInputField(
'text', $id, $attributes);
115 function fixPostValue ($value)
118 return str_replace([
"\r\n",
"\r"],
"\n", $value);
123 $error = parent::check();
124 if (!empty($error)) {
127 if ($this->value !==
"") {
128 return $this->validate();
135 if (($this->pattern !==
'') && !preg_match($this->pattern, $this->value)) {
143 function setAutocomplete ($autocomplete)
145 if (is_bool($autocomplete)) {
146 $this->autocomplete = ($autocomplete ?
'on' :
'off');
148 $this->autocomplete = $autocomplete;
152 function getAutocomplete ()
154 return $this->autocomplete;
157 function checkValue ($value)
159 if (!is_scalar($value) && (!is_object($value) || !method_exists($value,
'__toString'))) {
160 throw new InvalidValueException(sprintf(_(
'StringAttribute "%s" was set to a non-compatible value'), $this->getLabel()));
164 function setValue ($value)
167 return parent::setValue(trim($value));
169 return parent::setValue($value);
179 protected $trim = TRUE;
187 function renderFormInput ():
string 189 $id = $this->getHtmlId();
190 $display =
'<textarea name="'.$id.
'" id="'.$id.
'"'.
191 ($this->disabled ?
' disabled="disabled"' :
'').
192 ($this->isSubAttribute ?
' class="subattribute"' : ($this->isRequired() ?
' required="required"' :
'')).
194 '{literal}'.
htmlescape($this->getValue()).
'{/literal}</textarea>';
198 function renderTemplateInput ():
string 200 $id = $this->getHtmlId();
201 $display =
'<textarea name="'.$id.
'" id="'.$id.
'"'.
202 ($this->disabled ?
' disabled="disabled"' :
'').
203 ($this->isSubAttribute ?
' class="subattribute"' :
'').
205 '{literal}'.htmlescape($this->getValue()).
'{/literal}</textarea>';
215 protected $autocomplete =
'new-password';
216 protected $inputType =
'password';
htmlescape(string $str)
Escape string for HTML output.
Exception class which can be thrown if an attribute is set to a value with a non-compatible type...
static invalidValue(string $error)
Format error message for invalid value.
Error returned by check method of SimplePlugin.
This class allow to handle easily a String LDAP attribute that appears as a text area.
This class allow to handle easily a String LDAP attribute that contains a password.
renderAcl(string $display)
Add ACL information around display.
This class allow to handle easily a String LDAP attribute that appears as a text area.
__construct($label, $description, $ldapName, $required=FALSE, $defaultValue="", $acl="", $regexp="", $example=NULL)
The constructor of StringAttribute.
This class allow to handle easily any kind of LDAP attribute.
This class allow to handle easily a String LDAP attribute.