So i found the problem:
Somwhere along the way while PFBC creates the Select element, it uses the third parameter (in my example, $area
or $ppl
) to generate an internal property called options
, probably to cover itself against single arrays of the type ["name", "name2", "name3"]
, inside OptionElement.php
the following code is causing problems.
public function __construct($label, $name, array $options, array $properties = null) {
$this->options = $options;
if(!empty($this->options) && array_values($this->options) === $this->options)
$this->options = array_combine($this->options, $this->options);
parent::__construct($label, $name, $properties);
}
The error is here: array_values($this->options) === $this->options
in my second array, $ppl
, i have a perfectly indexed table starting from zero
$ppl = [
0 => "name",
1 => "name2",
2 => "name3"
]
this triggers the control to think i have a simple array instead of custom keys, as:
$array_values($ppl) === $ppl
returns boolean(true)
The second array, $area is different, since it has missing keys:
$area = [
0 => "name",
10=> "name2",
11=> "name3"
]
So $array_values($area) === $area
returns boolean(false)
My solution, before touching PFBC (might be a bug, there has to be a better way to detect this case):
Change the database so $ppl
starts from 1
instead of 0
$ppl = [
1 => "name",
2 => "name2",
3 => "name3"
]
Incidentally then $array_values($ppl) === $ppl
returns boolean(false)
And now my Select works as i expected:
<select id="person" required="" name="person">
<option value="1">
name
</option>
<option value="2">
name2
</option>
<option value="3">
name3
</option>
</select>
Hope this helps!