Open tempfirstuser opened 3 years ago
@tempfirstuser Unfortunately, I cannot reproduce the error message. Can you provide a full example which allows to reproduce the problem? Another option is an unit test. Thanks!
For sake of completeness, this has also been discussed in Slack: https://laminas.slack.com/archives/C4QBQUEG5/p1623930860223800
@froschdesign , I have this generated html code:
<input type="hidden" name="categories" value="">
<input type="checkbox" name="categories[]" value="12">
<input type="checkbox" name="categories[]" value="34">
<input type="checkbox" name="categories[]" value="56">
if I checked some checkboxes I will have POST array of categories, something like this:
$_POST = [
'categories' => [
12,
34,
56
]
];
But if I will not check any of checkboxes I will have value from hidded input like this:
$_POST = [
'categories' => ''
];
which means instead of array I will get empty string. Was this helpful? Currently, I don't use 'use_hidden_element' => true,
and check if categories
is isset()
within POST
and if not I add categories
with value of empty array to the POST.
@tempfirstuser
I have the same HTML output and can not reproduce the error message:
File:
/vendor/laminas/laminas-inputfilter/src/ArrayInput.php:26
Message:
Value must be an array, string given.
So I need the definition of your form with input-filter.
@froschdesign , actually, I have nested array. I was trying to simplify the question. I have modified my post/issue at the top. fieldset and filter from the top is all what I have. In reality I have something nested like this:
$_POST = [
'product' => [
'categories' => ''
]
];
Do you have the same empty string:
$_POST = [
'categories' => ''
];
? Or do you have empty array like this:
$_POST = [
'categories' => []
];
?
@tempfirstuser
I have modified my post/issue at the top.
Okay, this helps! 👍
Please try to override the following:
With:
$hiddenAttributes = [
'name' => static::getName($element),
'value' => $uncheckedValue,
];
This will not work because the empty / unchecked value is always added to the array!
Bug Report
Summary
I have multicheckoxes. I want to have ability to return empty array if non of checkboxes is checked. I use
use_hidden_element
to return hidden input element instead but it returns empty string instead of empty array.This is my fieldset config:
this is my input filter config:
this is generated hidden input:
this is generated checkbox input:
and as result I've got this exception: