Fix handling "0" (zero string) value

This commit is contained in:
Benjamin Renard 2020-09-11 13:34:42 +02:00
parent 822d777dfd
commit 052882eb49
7 changed files with 33 additions and 15 deletions

View file

@ -94,9 +94,8 @@ class LSattr_html extends LSlog_staticLoggerClass {
LSerror :: addErrorCode('LSform_06',$this -> name);
return;
}
if ($data) {
if (!is_null($data))
$element -> setValue($data);
}
return $element;
}

View file

@ -115,9 +115,10 @@ class LSattribute extends LSlog_staticLoggerClass {
* @retval boolean true
*/
public function loadData($attr_data) {
if ((!is_array($attr_data))&&(!empty($attr_data))) {
if (is_empty($attr_data) || $attr_data === false)
$attr_data = null;
elseif (!is_array($attr_data))
$attr_data = array($attr_data);
}
$this -> data = $attr_data;
return true;
}
@ -231,13 +232,13 @@ class LSattribute extends LSlog_staticLoggerClass {
if($this -> myRights() == 'n') {
return true;
}
if ($value) {
if (!is_null($value)) {
$data = $value;
}
else if($this -> data !='') {
else if(!is_empty($this -> data)) {
$data = $this -> getFormVal();
}
else if ($this -> getConfig('default_value')) {
else if (!is_empty($this -> getConfig('default_value'))) {
$data = $obj -> getFData($this -> getConfig('default_value'));
}
else {
@ -338,11 +339,11 @@ class LSattribute extends LSlog_staticLoggerClass {
LSerror :: addErrorCode('LSattribute_09',array('type' => 'html','name' => $this -> name));
return;
}
if($this -> data !='') {
$data=$this -> getFormVal();
if(!is_empty($this -> data)) {
$data = $this -> getFormVal();
}
else {
$data='';
$data=null;
}
$element = $this -> html -> addToForm($form,'view',$data);
if(!$element instanceof LSformElement) {

View file

@ -412,7 +412,7 @@ class LSform extends LSlog_staticLoggerClass {
*/
public function checkRequired($data) {
foreach($data as $val) {
if (!empty($val)||(is_string($val)&&($val=="0")))
if (!is_empty($val))
return true;
}
return;

View file

@ -258,7 +258,7 @@ class LSformElement extends LSlog_staticLoggerClass {
$post[$name] = array($post[$name]);
}
foreach($post[$name] as $key => $val) {
if (!empty($val)||(is_string($val)&&($val=="0"))) {
if (!is_empty($val)) {
$return[$key] = $val;
}
}

View file

@ -122,7 +122,7 @@ class LSformElement_labeledValue extends LSformElement {
}
foreach($_POST[$this -> name."_labels"] as $key => $label) {
$val=$_POST[$this -> name."_values"][$key];
if (!empty($label) && (!empty($val)||(is_string($val)&&($val=="0")))) {
if (!empty($label) && !is_empty($val)) {
$return[$this -> name][$key] = "[$label]$val";
}
}

View file

@ -314,14 +314,14 @@ class LSldap extends LSlog_staticLoggerClass {
$drop = true;
if (is_array($attrVal)) {
foreach($attrVal as $val) {
if (!empty($val)||(is_string($val)&&($val=="0"))) {
if (!is_empty($val)) {
$drop = false;
$changed_attrs[$attrName][]=$val;
}
}
}
else {
if (!empty($attrVal)||(is_string($attrVal)&&($attrVal=="0"))) {
if (!is_empty($val)) {
$drop = false;
$changed_attrs[$attrName][]=$attrVal;
}

View file

@ -764,3 +764,21 @@ function format_callable($callable) {
else
return $callable."()";
}
function is_empty($val) {
switch(gettype($val)) {
case "boolean":
case "integer":
case "double":
case "object":
case "resource":
return False;
case "array":
case "string":
if ($val == "0") return false;
return empty($val);
case "NULL":
return True;
}
return empty($val);
}