diff --git a/src/includes/class/class.LSattr_html.php b/src/includes/class/class.LSattr_html.php index d67dabaa..4497da80 100644 --- a/src/includes/class/class.LSattr_html.php +++ b/src/includes/class/class.LSattr_html.php @@ -29,11 +29,24 @@ LSsession :: loadLSclass('LSlog_staticLoggerClass'); */ class LSattr_html extends LSlog_staticLoggerClass { + // The attribute name var $name; + + // The attribute configuration var $config; + + // The reference of the parent LSattribute object var $attribute; + + // The corresponding LSformElement object type var $LSformElement_type = false; + // If true, this LSattr_html type is considered as able to only support + // the first and unique value of the attribute. If more than one value + // is passed to this LSattr_html type, an LSattr_html_03 error will be + // triggered. + protected $singleValue = false; + /** * Constructeur * @@ -94,8 +107,16 @@ class LSattr_html extends LSlog_staticLoggerClass { LSerror :: addErrorCode('LSform_06',$this -> name); return; } - if (!is_null($data)) - $element -> setValue($data); + if (!is_null($data)) { + $data = ensureIsArray($data); + if ($this -> singleValue) { + if (count($data) > 1) + LSerror :: addErrorCode('LSattr_html_03', get_class($this)); + $element -> setValue($data[0]); + } + else + $element -> setValue($data); + } return $element; } @@ -144,5 +165,5 @@ ___("LSattr_html : The method addToForm() of the HTML type of the attribute %{at ); // 02 : not yet used LSerror :: defineError('LSattr_html_03', -___("LSattr_html_%{type} : Multiple data are not supported for this field type.") +___("%{type} : Multiple data are not supported for this field type.") ); diff --git a/src/includes/class/class.LSattr_html_image.php b/src/includes/class/class.LSattr_html_image.php index 3117824b..d1d6e90f 100644 --- a/src/includes/class/class.LSattr_html_image.php +++ b/src/includes/class/class.LSattr_html_image.php @@ -27,29 +27,7 @@ */ class LSattr_html_image extends LSattr_html { - /** - * Ajoute l'attribut au formualaire passer en paramètre - * - * @param[in] &$form LSform Le formulaire - * @param[in] $idForm L'identifiant du formulaire - * @param[in] $data Valeur du champs du formulaire - * - * @retval LSformElement L'element du formulaire ajouté - */ - function addToForm (&$form, $idForm, $data=NULL) { - $element=$form -> addElement('image', $this -> name, $this -> getLabel(), $this -> config, $this); - if(!$element) { - LSerror :: addErrorCode('LSform_06',$this -> name); - return; - } - - if ($data && count($data) > 1) { - LSerror :: addErrorCode('LSattr_html_03','password'); - } - - if ($data) - $element -> setValue(ensureIsArray($data)[0]); - return $element; - } + var $LSformElement_type = 'image'; + protected $singleValue = true; } diff --git a/src/includes/class/class.LSattr_html_password.php b/src/includes/class/class.LSattr_html_password.php index 9d32cbcb..2f6e16d6 100644 --- a/src/includes/class/class.LSattr_html_password.php +++ b/src/includes/class/class.LSattr_html_password.php @@ -27,29 +27,7 @@ */ class LSattr_html_password extends LSattr_html { - /** - * Ajoute l'attribut au formualaire passer en paramètre - * - * @param[in] &$form LSform Le formulaire - * @param[in] $idForm L'identifiant du formulaire - * @param[in] $data Valeur du champs du formulaire - * - * @retval LSformElement L'element du formulaire ajouté - */ - public function addToForm (&$form,$idForm,$data=NULL) { - $element = $form -> addElement('password', $this -> name, $this -> getLabel(), $this -> config, $this); - if(!$element) { - LSerror :: addErrorCode('LSform_06', $this -> name); - return; - } - - if ($data) { - $data = ensureIsArray($data); - if (count($data) > 1) - LSerror :: addErrorCode('LSattr_html_03', 'password'); - $element -> setValue($data[0]); - } - return $element; - } + var $LSformElement_type = 'password'; + protected $singleValue = true; } diff --git a/src/includes/class/class.LSattr_html_select_object.php b/src/includes/class/class.LSattr_html_select_object.php index 27c79ce1..6a742150 100644 --- a/src/includes/class/class.LSattr_html_select_object.php +++ b/src/includes/class/class.LSattr_html_select_object.php @@ -27,6 +27,7 @@ */ class LSattr_html_select_object extends LSattr_html{ + var $LSformElement_type = 'select_object'; var $unrecognizedValues=false; /** @@ -40,7 +41,7 @@ class LSattr_html_select_object extends LSattr_html{ */ public function addToForm (&$form,$idForm,$data=NULL) { $this -> config['attrObject'] = $this; - $element=$form -> addElement('select_object', $this -> name, $this -> getLabel(), $this -> config, $this); + $element=$form -> addElement($this -> LSformElement_type, $this -> name, $this -> getLabel(), $this -> config, $this); if(!$element) { LSerror :: addErrorCode('LSform_06',$this -> name); return;