New class DomainListInputFormField for alias list validation upon account creation

This commit is contained in:
Ludovic Poujol 2019-03-19 18:38:17 +01:00
parent 93aeb193ee
commit 3469dcfcd5
2 changed files with 54 additions and 2 deletions

View File

@ -456,6 +456,58 @@ class DomainInputFormField extends FormField {
}
}
class DomainListInputFormField extends FormField {
protected $mandatory = NULL;
protected $textsize = NULL;
public function __construct($label, $mandatory=TRUE) {
parent::__construct($label);
$this->mandatory = $mandatory;
$this->textsize = $textsize;
}
public function verify($set_error) {
if($this->mandatory && (!strlen($this->value))) {
if($set_error) $this->error = 'Champ obligatoire';
return FALSE;
}
if(strlen($this->value)){
$list = explode(',', $this->value);
foreach ($list as $value) {
if (!preg_match("/^[a-z0-9-.]+\.[a-z]{2,}$/i", $value)) {
if($set_error) $this->error = 'Ceci n\'est pas un nom de domaine';
return FALSE;
}
}
}
return TRUE;
}
public function getInputHTML() {
$input = '';
$input .= '<input type="text" id="'.$this->name.'"';
$input .= ' name="'.$this->name.'" value="'.htmlspecialchars($this->value,ENT_QUOTES).'"';
$input .= ' maxlength="'.$this->textsize[1].'" size="'.$this->textsize[0].'" ';
if($this->read_only) { $input .= 'readonly="readonly="'; }
if($this->disabled) { $input .= 'disabled="disabled="'; }
$input .= '/>';
return $input;
}
public function __toString() {
$out = '';
$out .= "<p>\n";
$out .= $this->getLabelHTML();
$out .= $this->getInputHTML();
$out .= $this->getErrorHTML();
$out .= "</p>\n\n";
return $out;
}
}
class DateInputFormField extends TextInputFormField {
public function __construct($label, $mandatory=TRUE) {
parent::__construct($label, $mandatory, array(7, 10));

View File

@ -252,8 +252,8 @@ function web_add_cluster($form, $admin_mail) {
$form = new FormPage("Ajout d'un compte web", FALSE);
$form->addField('username', new TextInputFormField("Nom d'utilisateur", TRUE, array(20,16)));
$form->addField('domain', new DomainInputFormField("Nom de domaine", TRUE));
$form->addField('domain_alias', new TextInputFormField("Alias (séparés par une virgule)", FALSE));
$form->addField('password_random',
$form->addField('domain_alias', new DomainListInputFormField("Alias (séparés par une virgule, sans espaces)", FALSE));
$form->addField('password_random',
new CheckboxInputFormField("Mot de passe aléatoire ?", FALSE));
$form->getField('password_random')->setValue(TRUE);
$form->addField('password', new PasswordInputFormField('Mot de passe', FALSE));