Stop Widget::get_array() creating unwanted indexes

When some widgets checked for value in beforeSendToClient() or validate(), they were accidentally creating a numeric index in nm content.  When these indexes built up over several submits, they caused problems with grids with repeating rows.

Fixes addressbook organisation column goes missing
This commit is contained in:
nathan 2023-02-03 11:31:39 -07:00
parent 888c3f30a2
commit 1faeffebee
4 changed files with 12 additions and 11 deletions

View File

@ -52,7 +52,7 @@ class Box extends Etemplate\Widget
if ($this->id && $this->type != 'groupbox') $cname = self::form_name($cname, $this->id, $params[1]);
if (($expand['cname'] ?? null) !== $cname && trim($cname))
{
$expand['cont'] =& self::get_array(self::$request->content, $cname);
$expand['cont'] =& self::get_array(self::$request->content, $cname, false, true);
$expand['cname'] = $cname;
}
if ($respect_disabled && isset($this->attrs['disabled']) && self::check_disabled($this->attrs['disabled'], $expand))

View File

@ -433,7 +433,7 @@ class Customfields extends Transformer
}
$all_readonly = $this->is_readonly($cname, $form_name);
$value_in = self::get_array($content, $form_name);
$value_in = self::get_array($content, $form_name, false, true);
$use_private = self::expand_name($this->attrs['use-private'] ?? null, 0, 0, '', '', self::$cont);
// if we have no id / use self::GLOBAL_ID, we have to set $value_in in global namespace for regular widgets validation to find
if (!$this->id) $content = array_merge($content, (array)$value_in);

View File

@ -207,11 +207,11 @@ class Grid extends Box
default:
return false;
}
if ($Ok && ($fname=self::form_name($cname, $child->id, $expand)) &&
if($Ok && ($fname = self::form_name($cname, $child->id, $expand)) &&
// need to break if fname ends in [] as get_array() will ignore it and returns whole array
// for an id like "run[$row_cont[appname]]"
substr($fname, -2) != '[]' &&
($value = self::get_array(self::$request->content,$fname)) !== null) // null = not found (can be false!)
($value = self::get_array(self::$request->content, $fname, false, true)) !== null) // null = not found (can be false!)
{
//error_log(__METHOD__."('$cname', ) $this autorepeating row $expand[row] because of $child->id = '$fname' is ".array2string($value));
unset($value);

View File

@ -67,16 +67,17 @@ class Link extends Etemplate\Widget
{
$attrs = $this->attrs;
$form_name = self::form_name($cname, $this->id, $expand);
$value =& self::get_array(self::$request->content, $form_name, true);
$value = self::get_array(self::$request->content, $form_name, false, true);
if($value && !is_array($value) && !($this->attrs['onlyApp'] ?? $this->attrs['only_app']))
{
// Try to explode
if(count(explode(':',$value)) < 2)
if(count(explode(':', $value)) < 2)
{
throw new Api\Exception\WrongParameter("Wrong value sent to $this, needs to be an array. ".array2string($value));
throw new Api\Exception\WrongParameter("Wrong value sent to $this, needs to be an array. " . array2string($value));
}
list($app, $id) = explode(':', $value,2);
$value =& self::get_array(self::$request->content, $form_name, true);
list($app, $id) = explode(':', $value, 2);
$value = array('app' => $app, 'id' => $id);
}
elseif (!$value)
@ -383,7 +384,7 @@ class Link extends Etemplate\Widget
if (!$this->is_readonly($cname, $form_name))
{
$value = $value_in =& self::get_array($content, $form_name);
$value = $value_in =& self::get_array($content, $form_name, false, true);
// keep values added into request by other ajax-functions, eg. files draged into htmlarea (Vfs)
if((!$value || is_array($value) && !$value['to_id']) && is_array($expand['cont'][$this->id]) && !empty($expand['cont'][$this->id]['to_id']))
@ -402,7 +403,7 @@ class Link extends Etemplate\Widget
return;
}
// Link widgets can share IDs, make sure to preserve values from others
$already = self::get_array($validated, $form_name);
$already = self::get_array($validated, $form_name, false, true);
if($already != null)
{
$value = array_merge((array)$value, $already);
@ -450,7 +451,7 @@ class Link extends Etemplate\Widget
);
}
}
$valid =& self::get_array($validated, $form_name, true);
$valid =& self::get_array($validated, $form_name, true, is_null($value));
if (true) $valid = $value;
//error_log($this);
//error_log(" " . array2string($valid));