So I am using CakePHP and I need to POST array of values. How it should be done? Either by creating input for every element or one input with all elelents. First one is fine with the convention, but pumping DOM with dozens of inputfields feels counter-productive.
So witch approach is considered as good practice?
foreach($tms['deletable'] as $tm){
echo $this->Form->control("ids[]", [
"type" => "hidden",
"value" => $tm->id,
]);
}
Or
echo $this->Form->control("ids", [
"type" => "hidden",
"value" => implode(",",collection($tms['deletable'])->extract("id")->toList())
]);
I'd say if you don't plan to modify the hidden field values in JavaScript, then go with the one field.
On the other hand, it requires you to do special handling on the receiving side (exploding), so use multiple fields.
A dozen fields are nothing if you look at the bloated HTML pages these days.